In my project I do it like this:
- I define a manual layout for the notification
- In the layout, I add
ImageButtons
- I define a
selector
for background of the ImageButtons
(would be possible for the source, too)
- Finally, I manually set the layout of the Notification as given here
- Of course, I also add a
PendingIntent
but as you already do that, I don't detail it here
The xml-layout-file contains ImageButtons
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp" <!-- This is where I manually define the height -->
android:orientation="horizontal" >
<ImageButton
android:id="@+id/big_notification_cancel_button"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@drawable/notification_button_background_selector"
android:src="@drawable/some_image_with_transparent_background"
/>
<!-- some more elements.. -->
</LinearLayout>
The notification_button_background_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="true"
android:drawable="@drawable/white_semi_opaque_background"/>
<item
android:drawable="@drawable/transparent_background"/>
</selector>
I'm not sure if this is really the answer you're looking for. Hope it helps, though.
Edit:
I have worked with the change of Image for ImageView, too. You have to update the View after you receive a click.
In the class where I update the notification, I do this:
RemoteViews smallViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout_big);
if(playing){
smallViews.setImageViewResource(R.id.big_notification_button_play_pause, R.drawable.notification_small_pause_button_selector);
}else{
smallViews.setImageViewResource(R.id.big_notification_button_play_pause, R.drawable.notification_small_play_button_selector);
}
// and some more stuff