ysh*_*hak 21 notifications android android-layout
我想在其中不断显示小图标status bar,而不显示notification系统托盘上的通知本身.
我尝试使用自定义layout并将根元素的可见性设置为View.GONE,或者View.INVISIBLE,对于两者,系统忽略它.
我也尝试设置根元素的高度,但系统也忽略了这一点.
这是我的代码:
R.layout.custom_notification:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_notification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/notif_background"
android:orientation="horizontal"
android:baselineAligned="false"/>
Run Code Online (Sandbox Code Playgroud)
并显示以下代码Notification:
NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx);
mBuilder
.setSmallIcon(drawableId)
.setAutoCancel(false)
.setOngoing(true)
.setPriority(Notification.PRIORITY_MAX);
Intent resultIntent = new Intent(ctx, SettingsActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(ctx, 0, resultIntent, 0);
mBuilder.setContentIntent(resultPendingIntent);
int layout = R.layout.custom_notification ;
RemoteViews contentView = new RemoteViews(ctx.getPackageName(), layout);
contentView.setViewVisibility(R.id.custom_notification, View.INVISIBLE);
mBuilder.setContent(contentView);
nm.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)
我很清楚,为了实现我的目标,我不需要记录解决方案.而且我也知道UX准则强烈建议不做这样的事情.所以没有必要把这个作为答案写给我.
Tap*_*nHP 10
根据开发人员文档,显示图标而不向他显示任何相关通知并不是一个好主意.
状态栏通知需要以下所有条件:
因此,如果您不想破坏用户体验,那么强烈建议您遵循UX准则,
逻辑上:状态栏有两部分 - 用户(通知)和系统(其他).如果系统允许将某些东西放到系统部分 - 会有太多无用的图标(由其他应用程序发布),并且没有一致性,并且可能会破坏所有使用体验.
找到了一个答案,为您提供的方式来访问报警的默认状态栏图标,它是在这里.根你的手机你可以做到这一点.在youtube上做一些技巧,同一主题的一些答案建议使用通知显示图标,但将通知文本放空,以便用户只能看到图标,但同样不是一种方式.
这是系统中状态栏实现的代码,其中描述了左右图标(即系统图标),您可以从那里获得一些优势.描述它的答案就在这里.
我建议不要使用usuall Google Play应用程序.有几个原因:
如果你发现一个有助于显示隐形通知的错误,它似乎没什么.该错误仅适用于具有特定Android版本的部分设备.请记住:使用打开的API在大多数设备中正确执行常规代码非常困难.隐藏的API不适用于所有设备.
源代码中没有这样的行为:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/app/NotificationManager.java# NotificationManager.notify%28int%2Candroid.app.Notification%29 .你无法找到这样的行为.
要预测行为,请使用Android的Compat类.也就是说,通知只使用NotificationCompat类!只有使用包装器才能帮助您的应用显示通知.
这是非常非常丑陋的UI/UX.
通知的工作流程在很大程度上取决于Android版本.
| 归档时间: |
|
| 查看次数: |
5609 次 |
| 最近记录: |