Android 如何正确设置通知区域中的图标?
我正在尝试为我的Android应用程序在通知区域设置一个图标 我注意到股票行情中的图标似乎被切断了。当股票代码消失时,通知区域中的图标看起来很好。下面是我设置图标的代码:Android 如何正确设置通知区域中的图标?,android,android-layout,Android,Android Layout,我正在尝试为我的Android应用程序在通知区域设置一个图标 我注意到股票行情中的图标似乎被切断了。当股票代码消失时,通知区域中的图标看起来很好。下面是我设置图标的代码: String msg = "Calculation completed. Tap to view result."; final Intent restartActivityIntent = new Intent(context, NumberOfPrimesActivity.class); final PendingInte
String msg = "Calculation completed. Tap to view result.";
final Intent restartActivityIntent = new Intent(context, NumberOfPrimesActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, restartActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews mContentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification);
mContentView.setImageViewResource(R.id.image, R.drawable.two);
mContentView.setTextViewText(R.id.text, msg);
Notification.Builder notificationBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.two).setContentTitle("Sum of Primes").setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent).setTicker(msg);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, notificationBuilder.build());
以下是我的通知的自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#7777"
android:padding="3dp">
<ImageView android:id="@+id/image"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginRight="10dp"
android:contentDescription="alert"
android:src="@drawable/two" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:textSize="24sp" />
</LinearLayout>
下面是我的res
目录的外观:
ldpi
文件夹中的two.png
文件是22x22
最后,这里有两个截图。第一个显示的是剪掉图标的股票代码。第二个图标在股票行情消失后显示。图标在第二个屏幕截图中看起来不错
更新
mdpi
文件夹中的two.png
文件是48x48
hdpi
文件夹中的two.png
文件是72x72
xhdpi
文件夹中的two.png
文件是92x92
xxhdpi
文件夹中的two.png
文件是144x144
我正在使用模拟器来测试我的程序。我有两个模拟器。一个是Nexus7(800 x 1280),另一个是Nexus4(768 x 1280)
在两个模拟器上,股票代码中的图标都被切断。无论出于何种原因,股票代码视图中的图标不会自动调整大小,但在通知视图中会自动调整大小 根据“通知图标必须为24x24 dp”,在不同的屏幕密度下可转换为以下尺寸: ldpi:18x18px
mdpi:24x24px
hdpi:36x36px
xhdpi:48x48px
因此,如果您相应地调整
res
文件夹中的两个.png
图标的大小,则该图标不会在“股票代码”和“通知”视图中被切断。无论出于何种原因,股票代码视图中的图标都不会自动调整大小,但在“通知”视图中会自动调整大小
根据“通知图标必须为24x24 dp”,在不同的屏幕密度下可转换为以下尺寸:
ldpi:18x18pxmdpi:24x24px
hdpi:36x36px
xhdpi:48x48px
因此,如果您相应地调整
res
文件夹中的2个.png
图标的大小,则该图标不会在股票代码视图和通知视图中被切断。屏幕截图中设备的屏幕密度是多少?其他文件夹中的two.png的尺寸是多少?我刚刚更新了我的问题。截图中设备的屏幕密度是多少?其他文件夹中two.png的维度是多少?我刚刚更新了我的问题。