1

I noticed notifications layouts have rounded edges

enter image description here

And mine has sharp corners

enter image description here

I tried rounding the corners with a drawable

<?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>

I got close, but it's really not the same.

How do I get rounded edges the standard way?

edit

Here is my code. Got the panel set in my main activity. Credit goes here.

NotificationPanel nPanel = new NotificationPanel(this);

And here are my NotificationPanel class

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);
    }
}

Here is the notifications view layout

<?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>
Community
  • 1
  • 1
the_prole
  • 8,275
  • 16
  • 78
  • 163
  • Is your bar shown in the notification list as well? And do you want exactly the same corners like on the screenshot or would you prefer inheriting the default android style (as this might be different from version to version/phone to phone)? – Tobias Baumeister Jan 10 '16 at 00:46
  • I would like the corners to be the same as the other notifications. I also want uniformity across all devices. What do you mean by notifications list? If you mean do they all drop down from the top of screen, then yes. – the_prole Jan 10 '16 at 00:48
  • Yes, that's what I meant. Do you have a bit of a code that you can show in which you create the box? // Nevermind, reading your edit now. – Tobias Baumeister Jan 10 '16 at 00:50
  • Yeah, thanks. I just added it. – the_prole Jan 10 '16 at 00:51
  • I might be wrong, but try removing the `android:background` attribute from the `LinearLayout`. Maybe that is covering the default background (with the corners) in the background. – Tobias Baumeister Jan 10 '16 at 00:58
  • Oh wow, you're right. How does one change the background color then? Maybe I should nest another layout inside the parent? EDIT: Nope, didn't work. – the_prole Jan 10 '16 at 01:00
  • I don't think there is a way to do that, unfortunately. You'd either have to use the default background completely; or hide it with your own Layout. Also please really keep in mind that notifications look extremely different on different devices. Just search for "android notifications" on google images and you will see. Setting rounded corners and a pale custom color may look nice on your device, but very irritating on another device. Therefore it's normally recommended to keep the default background, at least for notifications. – Tobias Baumeister Jan 10 '16 at 01:06
  • Huh, I just wonder how all the other applications on my phone manage to customize the background color while maintaining the default shape. – the_prole Jan 10 '16 at 01:08
  • Actually what I discovered, is there are apparently only 3 colors which are determined by the material design theme. See [here](http://stackoverflow.com/questions/30560279/android-lollipop-notification-background-colour) – the_prole Jan 10 '16 at 23:33

1 Answers1

1

Instead of making your own layout with listeners and other customizations, you might want to try adding actions to the notification and then tweaking it to your liking - it will likely work better across various APIs and look more standard:

// 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();
jt-gilkeson
  • 2,661
  • 1
  • 30
  • 40
  • Thanks. This post [here](http://stackoverflow.com/questions/13902115/how-to-create-a-notification-with-notificationcompat-builder) also helped a lot. – the_prole Jan 10 '16 at 23:34