你好。我创建了一个完全自定义的通知视图。但是在不同设备上,左侧(开始)边距不同。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:orientation="vertical"
android:layout_marginEnd="@dimen/notificationContentInsert"
android:layout_marginStart="@dimen/notificationContentInsert"
>
在 values/dimens.xml 中,notificationContentInsert 的值为16dp。
例如:
在我的 OnePlus 6(1080 x 2280)上,所有通知(包括系统通知和其他应用程序如 Gmail)的起始边距都为16dp,看起来很好。
但是,在三星 Tab A(9.7 英寸,1024x768)上,16dp 看起来比其他通知更小。
我也尝试使用 sdk 属性 android:dimen/notification_content_margin_start,但该属性是私有的,我得到了编译异常AAPT: error: resource android:dimen/notification_content_margin_start is private.
是否有办法获取设备指定的通知内容填充?谢谢。