Pregunta

I need to dynamically set the icon in the title bar. Currently I have this code in my activity:

requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.table_layout_activity);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon_procedure);

This works fine, except that it changes the font size and it removes the (default) border line at the bottom of the bar. I'd like to only set the icon and leave everything else as default.

Default title bar:

Default titlebar.

Custom icon:

Custom icon.

Anyone can help?

¿Fue útil?

Solución

Icon can be changed in multiple ways for Activities, programmatically for an individual activity as

In onCreate()

getActionBar().setIcon(R.drawable.icon);
// icon is image in res/drawable folder.

Or in actionbar theme, by adding this to your ActionBar style.

<item name="android:icon">@drawable/icon</item>
<!-- This changes icon universally for all Activities in application -->

Otros consejos

Since you are using the action bar, use setIcon() on ActionBar to change the icon, and get rid of that other stuff.

Use setIcon() on actionBar() or change it directly in androidManifest.xml

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top