PHP/C#/ASP 编码器在给 Xamarin 一个镜头后正确地开始在 android 中(然后有 6 个月的中断所有编码)。
我正在尝试在通知中实现自定义布局。我可以让它产生正常的通知,但是当它使用 setContent(view) 完成时我忍不住崩溃。
也是 Eclipse/ADT 的新手,所以很难知道如何自己解决问题(在 visual studio 中这很容易)。
澄清一下,displayNotification 当前设置为在应用启动时执行。
我确信它是如此简单和小,但是已经很晚了,我的头脑很疲惫。非常感谢所有帮助!
这是我的代码(删除了所有注释掉的代码只是为了清理它)。
protected void displayNotification() {
RemoteViews customNotificationView =
new RemoteViews(getPackageName(), R.layout.notification_layout);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this);
mBuilder.setContent(customNotificationView);
mBuilder.setTicker("New Message Alert!");
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setOngoing(true);
mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notificationID, mBuilder.build());
}
这是我的自定义布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notification_title"
style="@style/NotificationTitle"
/>
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
最佳答案
我测试了您的代码,它似乎在布局中没有 SeekBar 的情况下工作正常。基于此answer您不能在通知布局上添加搜索栏。 我会看起来更好,稍后评论。
编辑: 您可以尝试将搜索栏更改为按钮并为其添加 onClick 监听器,这是一个起点。 Adding onClick Action To Button In Notification
关于android - 使用 setContent 时自定义通知崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23819429/