原生的通知button交互上比较难用,直接上修改。
button布局不同机型位置具体情况按自己的设备设置好,下面是当前实现项目的布局,仅供参考.
frameworks\base\packages\SystemUI\res\layout\status_bar_expanded.xml
<ImageView
android:id="@+id/ic_clear_all_notification"
android:id=layout_width="wrap_content"
android:id=layout_height="wrap_content"
android:id=layout_graviity="center|bottom"
android:layout_marginBottom="25.0dip"
android:scaleType="fitXY"
android:src="@drawable/ic_clear_all_notification"
/>
Java代码修改:
frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\NotificationPanelView.java
protected void onFinishInflate() {
...
//add for notification clear button
mClearView =(ImageView)findViewById(R.id.ic_clear_all_notification);
mClearView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mStatusBar.clearAllNotifications();
}
});
//add for notification clear button
}
private void updateNotificationTranslucency() {
float alpha = 1f;
if (mClosingWithAlphaFadeOut && !mExpandingFromHeadsUp && !mHeadsUpManager.hasPinnedHeadsUp()) {
alpha = getFadeoutAlpha();
}
mNotificationStackScroller.setAlpha(alpha);
//add for notification clear button
KeyguardManager keyguardManager =
(KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager.isKeyguardLocked() || mHeadsUpManager.hasPinnedHeadsUp()) {
mClearView.setVisibility(View.INVISIBLE);
} else {
mClearView.setVisibility(ifHasActiveClearableNotifications() ? View.VISIBLE : View.INVISIBLE);
}
//add for notification clear button
}
控制button是否应该显示的关键方法
/**
* Return whether there are any clearable notifications
*/
private boolean ifHasActiveClearableNotifications() {
int childCount = mNotificationStackScroller.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = mNotificationStackScroller.getChildAt(i);
if (!(child instanceof ExpandableNotificationRow)) {
continue;
}
if (((ExpandableNotificationRow) child).canViewBeDismissed()) {
return true;
}
}
return false;
}
移除原生默认的DismissView的显示
frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\DismissView.java
protected void onFinishInflate() {
super.onFinishInflate();
mDismissButton = (DismissViewButton) findContentView();
+mDismissButton.setVisibility(View.GONE);
}
小小的记录一笔,欢迎指正交流.