android 自定义通知栏不显示

「已注销」 2015-06-06 05:11:05
public void onClick(View v){
try{
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification=new Notification();
//notification.icon=R.drawable.ic_launcher;
notification.flags=Notification.FLAG_AUTO_CANCEL;
RemoteViews remoteView=new RemoteViews(getPackageName(), R.layout.notifacation);
remoteView.setImageViewResource(R.id.imageView1, R.drawable.ic_launcher);
remoteView.setTextViewText(R.id.nstart, "play");
remoteView.setTextViewText(R.id.npause, "pause");
remoteView.setTextViewText(R.id.nquit, "quit");
notification.contentView=remoteView;//显示布局
Intent inte=new Intent(getApplicationContext(), MainActivity.class);
inte.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi=PendingIntent.getActivity(this, 0, inte, 0);
notification.contentIntent=pi;

notificationManager.notify(100,notification );
Log.d("testDIY", "ok");
}catch(Exception e){
e.printStackTrace();
}
这是要显示的代码,但是不知道为什么不显示
...全文
539 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
无奈袜子 2015-09-08
  • 打赏
  • 举报
回复
请问如何解决的???????
qq_15139779 2015-08-25
  • 打赏
  • 举报
回复
我跟你问题一模一样,不过加了一句
notification1.icon=R.drawable.ic_launcher;
就行了,这个ticker应该是启动通知栏的一个作用吧
「已注销」 2015-06-06
  • 打赏
  • 举报
回复
现在已经检测出来了 xml中不能有id
「已注销」 2015-06-06
  • 打赏
  • 举报
回复
<?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="wrap_content" > <ImageView android:id="@+id/imageView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:src="@android:drawable/stat_notify_chat" /> <Button android:id="@+id/nstart" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="play" android:onClick="nonClick" /> <Button android:id="@+id/npause" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="stop" android:onClick="nonClick" /> <Button android:id="@+id/nquit" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="quit" android:onClick="nonClick" /> </LinearLayout> 这是xml布局

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧