我注意到通知布局有圆角
我的角落很尖锐
我尝试使用可绘制的
来绕过角落<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#4d4d4d"/>
<corners android:radius="1dip"/>
</shape>
我接近了,但实际上并不相同。
如何以标准方式获得圆边?
修改
这是我的代码。在我的主要活动中设置了面板。积分为here。
NotificationPanel nPanel = new NotificationPanel(this);
这是我的NotificationPanel
课程
public class NotificationPanel {
private Context parent;
private NotificationManager nManager;
private NotificationCompat.Builder nBuilder;
private RemoteViews remoteView;
public NotificationPanel(Context parent) {
// TODO Auto-generated constructor stub
this.parent = parent;
nBuilder = new NotificationCompat.Builder(parent)
.setContentTitle("Parking Meter")
.setSmallIcon(R.drawable.button_play)
.setOngoing(true);
remoteView = new RemoteViews(parent.getPackageName(), R.layout.notificationview);
//set the button listeners
setListeners(remoteView);
nBuilder.setContent(remoteView);
nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(2, nBuilder.build());
}
public void setListeners(RemoteViews view){
//listener 1
Intent volume = new Intent(parent,NotificationReturnSlot.class);
volume.putExtra("DO", "volume");
PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0);
view.setOnClickPendingIntent(R.id.btn1, btn1);
//listener 2
Intent stop = new Intent(parent, NotificationReturnSlot.class);
stop.putExtra("DO", "stop");
PendingIntent btn2 = PendingIntent.getActivity(parent, 1, stop, 0);
view.setOnClickPendingIntent(R.id.btn2, btn2);
}
public void notificationCancel() {
nManager.cancel(2);
}
}
这是通知视图布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="volume" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Stop" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/msglbl" />
</LinearLayout>
答案 0 :(得分:1)
您可能希望尝试向通知添加操作,然后根据自己的喜好调整通知,而不是使用侦听器和其他自定义设置自己的布局 - 它可能会在各种API中更好地工作并且看起来更标准:
// Set the style
NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(strMessage);
// Build the notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setTicker(ticker)
.setColor(context.getResources().getColor(R.color.notification_bg))
.setSmallIcon(R.drawable.status_bar_ic)
.setContentIntent(intent)
.setStyle(bigStyle)
.setWhen(0)
.setAutoCancel(true)
.setStyle(bigStyle)
.addAction(R.drawable.notification_volume_ic, getString(R.string.volume), pendingVolume)
.addAction(R.drawable.notification_stop_ic, getString(R.string.stop), pendingStop)
.setOngoing(true);
notificationBuilder.build();