【发布时间】:2016-01-10 09:14:29
【问题描述】:
我注意到通知布局有圆角
我的有尖角
我尝试用可绘制的圆角来圆角
<?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>
【问题讨论】:
-
您的栏是否也显示在通知列表中?您是否想要与屏幕截图中完全相同的角,还是更喜欢继承默认的 android 样式(因为这可能因版本/手机而异)?
-
我希望角落与其他通知相同。我还希望所有设备的一致性。通知列表是什么意思?如果您的意思是它们都从屏幕顶部下拉,那么是的。
-
是的,我就是这个意思。您是否有一些代码可以显示在其中创建框? // 没关系,现在阅读您的编辑。
-
是的,谢谢。我刚刚添加了它。
-
我可能错了,但请尝试从
LinearLayout中删除android:background属性。也许这覆盖了背景中的默认背景(带角)。
标签: android