문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top