第一步:新建一个工程,命名为cusNotification;
第二步:新建一个布局文件(即自定义的notification的布局文件:custom_notification.xml,内容如下:
第三步:新建上面布局文件中引用到的styles.xml文件,代码如下:
第二步:新建一个布局文件(即自定义的notification的布局文件:custom_notification.xml,内容如下:
1 2 3 4 5 6 7 8 9 10 | <!--?xml version= "1.0" encoding= "utf-8" ?--> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "match_parent" > <imageview android:id= "@+id/image" android:layout_width= "wrap_content" android:layout_height= "fill_parent" android:layout_alignparentleft= "true" android:layout_marginright= "10dp" android:contentdescription= "@string/Image" > <textview android:id= "@+id/title" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@id/image" style= "@style/NotificationTitle" > <textview android:id= "@+id/text" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@id/image" android:layout_below= "@id/title" style= "@style/NotificationText" > </textview></textview></imageview></relativelayout> |
第三步:新建上面布局文件中引用到的styles.xml文件,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!--?xml version= "1.0" encoding= "utf-8" ?--> <resources> <style name= "NotificationText" parent= "android:TextAppearance.StatusBar.EventContent" > <style name= "NotificationTitle" parent= "android:TextAppearance.StatusBar.EventContent.Title" /> </resources> </pre> 第四步:修改java源文件,代码如下: <pre class =\"brush:cpp;toolbar: false \"> public class CusNotificationActivity extends Activity { private static final int CUSTOM_VIEW_ID = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ; int icon = R.drawable.ic_launcher; CharSequence tickerText = "Notification01" ; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); contentView.setImageViewResource(R.id.image, R.drawable.notification_image); contentView.setTextViewText(R.id.title, "Custom notification" ); contentView.setTextViewText(R.id.text, "This is a custom layout" ); notification.contentView = contentView; Intent notificationIntent = new Intent( this , CusNotificationActivity. class ); PendingIntent contentIntent = PendingIntent.getActivity(CusNotificationActivity. this , 0, notificationIntent, 0); notification.contentIntent = contentIntent; String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); mNotificationManager.notify(CUSTOM_VIEW_ID, notification); } } </pre><p>本文链接:<a href= "https://it72.com:4443/232.htm" >https://it72.com:4443/232.htm</a></p> </ div > < div class = "plugin d-flex justify-content-center mt-3" > <style> .haya-favoriter { position: relative; } .haya-favorite-show-users { position: absolute; top: 5px; z-index: 100; width: 100%; } .haya-favorite-show-users .haya-favorite-users { max-height: 250px; overflow-y: auto ; } </style> < div class = "haya-favoriter px-2" > <span class = "btn-group haya-favoriter-info" role= "group" > <button class = "btn btn-outline-secondary js-haya-favorite-tip" data-tid= "232" title= "收藏本帖" > <i class = "icon icon-star-o" aria-label= "收藏本帖" ></i> <span class = "haya-favorite-btn" >收藏</span> </button> <button class = "btn btn-outline-secondary js-haya-favorite-show-users" data-tid= "232" title= "点击查看收藏详情" > <span class = "haya-favorite-user-count" >0</span> </button> </span> </ div > </resources> |
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2302
- 用户1336
- 访客10975106
每日一句
If you want to achieve greatness, stop asking for permission.
如果你想获得伟大,别再请求许可。
如果你想获得伟大,别再请求许可。
UAC的限制引起WM_DROPFILES无法响应的解决办法
MeasureSpec中三种模式:UNSPECIFIED,AT_MOST,EXACTLY
发几个实用的chrome插件
CentOS下使用 svnsync迁移SVN代码库
仙剑奇侠传3d回合-PC端辅助
【转载】C++实现EXE加载到内存执行
【收藏】OpenCV一些常用库函数
《闲来麻将》搭建教程
文本转语音系统Spark-TTS
wordpress转xiuno附件自动插入工具
Mac OS最简单及(Karabiner)快捷键设置
使用Putty上传文件?
ndk神奇问题之non-numeric second argument to `wordlist' function: '8.7z'
新会员