Pooks
Pooks

Reputation: 2585

Android: How to set icon in title bar of Dialog activity?

I declared a dialog activity in my Manifest as follows:

<activity android:name=".myDialog"
              android:label="@string/title_dlg"
              android:icon="@android:drawable/ic_dialog_alert"
              android:exported="false"
              android:excludeFromRecents="true"
              android:theme="@android:style/Theme.Dialog">

However, only the title's text appears in the title bar and the icon appears to be ignored. Is there a way to also show the icon in the title bar?

Upvotes: 12

Views: 13457

Answers (2)

Lior Iluz
Lior Iluz

Reputation: 26563

Use this after your super.onCreate(savedInstanceState); call:

requestWindowFeature(Window.FEATURE_LEFT_ICON);

Then, set your contentView(R.layout.youLayout); and then use this:

getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);

The order is important.

Upvotes: 26

ingsaurabh
ingsaurabh

Reputation: 15269

I think using below line after super call will work

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

Keep in mind to place it before setting content view

Upvotes: 1

Related Questions