The native notification button is more difficult to use interactively, so modify it directly.
The specific situation of the button layout of different models is set according to your own equipment. The following is the layout of the current implementation project, for reference only.
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 code modification:
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);
}
A small record, welcome to correct and communicate.