自定义Notification
来源:互联网 发布:阿里妈妈淘宝联盟区 编辑:程序博客网 时间:2024/06/05 00:41
可以通过Notification.Builder.setContent方法自定义Notification。setContent方法的原型如下:
public Builder setContent(RemoteViews views);
RemoteViews 是一种视图容器,只是这种视图容器支持的视图有限,目前RemoteViews 只支持布局和控件: 布局:FrameLayout、LinearLayout、RelativeLayout 控件:AnalogClock、Button、Chronometer、ImageButton、ImageView、ProgressBar、TextView RemoteViews类构造方法的原型如下:
public RemoteViews(String packageName, int layout);
packageName:包名 layout与RemoteViews对象关联的布局资源ID
public class NotificationActivity extends Activity { private NotificationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); } /** * 显示通知 * @param view */ public void showNotification(View view){ //创建RemoteViews对象 RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.notification); //设置布局中的TextView显示的文本 remoteViews.setTextViewText(R.id.tv001,"更新自定义文本内容"); //创建Builder对象 Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.person).setContent(remoteViews); //显示自定义的Notification manager.notify(1,builder.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" android:gravity="center"> <TextView android:id="@+id/tv001" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/black" android:gravity="center" android:textSize="20dp" android:text="自定义内容"/> <ImageView android:id="@+id/iv001" android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/person" /></LinearLayout>
0 0
- Notification&&自定义Notification
- 自定义notification
- 自定义Notification
- 自定义Notification
- 自定义Notification~~
- 自定义Notification
- 自定义Notification
- 自定义Notification
- 自定义Notification
- 自定义的Notification
- Android自定义Notification
- Android自定义Notification
- 使用自定义的 Notification
- 自定义Notification之进度条
- Android自定义Notification布局
- Android自定义Notification
- Android 自定义的notification
- 自定义的Notification布局
- 第10周项目1 -二叉树算法库
- mysql数据导入导出方法总结
- 安卓dp和px之间相互转换
- http协议、http事务、URL、http请求的方式、响应码信息、http1.0和1.1区别
- iOS 中的 21 种设计模式
- 自定义Notification
- vector元素的删除
- 从文件中读取数据
- Android Studio 查看不到SDK源码解决办法
- linux crontab 实现每隔几秒执行
- 第九周项目4建立广义表算法库
- nyoj 171 聪明的kk 第三届河南省赛
- Python + OpenCV实现基于傅里叶变换的旋转文本校正
- 接口与接口、接口与类之间的关系