在Jelly Bean中向通知添加操作时的灰色按钮

Chr*_*vik 10 android android-notifications android-4.2-jelly-bean

我在我的应用程序中添加了两个按钮,设置为目标API级别8.问题是两个按钮显示为两个大的灰色按钮,与其余通知完全不同.我已经在Nexus 7和Galaxy Nexus上测试了它.

在此输入图像描述

我见过的所有例子都有漂亮的黑色按钮,如来电通知:http: //www.androidng.com/wp-content/uploads/2012/07/android-jelly-bean-notifications.jpeg

我猜这很容易,但今天没有这样的运气.有谁知道我可能走错了路?下面是我的代码片段,它使用最新的支持库生成通知.

NotificationManager nm = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this);
    builder.setContentIntent(contentIntent)
                .setSmallIcon(R.drawable.ic_stat_radio)                
                .setContentTitle(message)
                .setTicker(message) 
                .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_HIGH)
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(false)                   
                .addAction(android.R.drawable.ic_btn_speak_now, "Play", contentIntent)
                .addAction(android.R.drawable.ic_dialog_map, "Stop", contentIntent)
                .setContentText(message);

    Notification n = builder.build();

    //nm.notify(0, n);
    startForeground(1, n);
Run Code Online (Sandbox Code Playgroud)

yin*_*ash 11

所以这发生了,因为AndroidManifest.xml中的targetSdk <11.

我相信当您定位11时发生的兼容性更改是默认主题,因为Holo.由于你的(和我的)目标小于11,它采用了一些适用于这些按钮的兼容性主题,即使它不应该.我假设即使您的应用/活动设置为Holo,它实际上也不适用于通知,因为它们处于不同的过程中.

这只是我的猜测.使用CommonsWare的通知演示只需修改targetSdk即可显示此行为.