我想将自定义布局显示为服务中的通知。
这是我在 Service 类中的方法:
private void fireNotification() {
Log.d("Clock", "Fire!");
if (this.remoteViews == null) {
Log.d("Clock", "!=null");
remoteViews = new RemoteViews(getPackageName(),
R.layout.custom_notification);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher).setContent(
remoteViews);
// Creates an explicit intent for an Activity in your app
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
mBuilder.setContentIntent(contentIntent);
startForeground(1, mBuilder.build());
}
}
custom_notification.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp"
android:background="@android:color/white"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#000" />
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:background="@android:drawable/ic_menu_help"
/>
</LinearLayout>
但是默认通知会显示我的图标!穿什么?
编辑:我在模拟器上运行我的应用程序,它可以在 Android 4 上运行,但在我的手机中使用姜饼,它无法正常工作!