美文网首页
RemoteViews 通知栏布局

RemoteViews 通知栏布局

作者: 主音King | 来源:发表于2020-10-13 13:44 被阅读0次

RemoteViews 通知栏显示ui差异

remoteViews = new RemoteViews(this.getPackageName(), R.layout.test);
 remoteViews.setImageViewResource(R.id.image, R.mipmap.app_icon);
remoteViews.setTextViewText(R.id.title, "测试");
 remoteViews.setTextViewText(R.id.text, "测试内容");
remoteViews.setTextViewText(R.id.time, showDate());
remoteViews.setTextViewText(R.id.time,时间);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelName).setContent(remoteViews)
                .setSmallIcon(R.mipmap.icon)
                .setContentIntent(clickIntent);

test.xml 自己定义

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginStart="10dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:scaleType="centerCrop" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_toLeftOf="@+id/time"
        android:layout_toRightOf="@+id/image"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:fadingEdge="horizontal"
            android:fadingEdgeLength="10dp"
            android:singleLine="true"
            android:text=""
            android:textColor="#000000"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/title"
            android:ellipsize="end"
            android:fadingEdge="horizontal"
            android:fadingEdgeLength="10dp"
            android:singleLine="true"
            android:text=""
            android:textColor="#000000"
            android:textSize="12sp" />
    </LinearLayout>
    <TextView
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_alignParentRight="true"
        android:textSize="11sp"
        android:textColor="#000000"
        android:text="下午 4:30"
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

在做音乐相关
通知栏在不同设备差异
华为手机:通知栏icon默认左间距无margin 需要添加10dp;通知栏默认背景可修改,通过自定义布局覆盖
小米手机:通知栏icon默认左间距有margin 大概10dp;通知栏默认背景为白色不可通过自定义布局覆盖
统一:icon为app图标;背景为白色;startMargin统一设置10dp;字体统一用黑色;

相关文章

  • RemoteViews 通知栏布局

    RemoteViews 通知栏显示ui差异 test.xml 自己定义 在做音乐相关通知栏在不同设备差异华为手机:...

  • (五)理解RemoteViews

    5.1 RemoteViews的应用 5.1.1 RemoteViews在通知栏上的应用 5.1.2 Remote...

  • Android 开发艺术探索笔记之五 -- 理解 RemoteV

    学习内容: RemoteViews 在通知栏和桌面小部件上的应用 RemoteViews 的内部机制 Remote...

  • Android View | RemoteViews使用及原理

    1. 应用场景 通知栏 桌面小控件 2. RemoteViews 原理 2.1 RemoteViews 不是一个 ...

  • 笔记:理解RemoteView

    理解RemoteView RemoteViews在安卓中的使用场景有通知栏通知和桌面小部件 通知栏主要通过Noti...

  • RemoteViews的应用

    5.1 RemoteViews的应用 RemoteViews在实际开发中,主要用在通知栏和桌面小部件的开发过程中。...

  • 第5章 理解 RemoteViews

    本章中,作者首先给我们介绍了 RemoteViews 在 Android 中通知栏和桌面小部件上的应用。通过通知栏...

  • RemoteViews

    RemoteViews在实际开发中,主要用于在通知栏和桌面小部件的开发过程中。 通知栏主要是通过Notificat...

  • Android通知笔记

    RemoteViews只支持部分布局和控件 当我们自定义通知布局的时候,需要通过NotificationCompa...

  • 自定义通知栏显示不全

    通过builder.setContent(remoteViews);给通知添加自定义界面,结果由于自定义界面布局过...

网友评论

      本文标题:RemoteViews 通知栏布局

      本文链接:https://www.haomeiwen.com/subject/sadvpktx.html