且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改操作栏图标

更新时间:2023-01-05 19:57:14

  getActionBar();
 

你扔的动作栏离开那里。 getActionBar()返回动作条的一个实例,然后您再需要调用的setIcon() 上。像这样:

 动作条动作条= getActionBar();
actionBar.setIcon(R.drawable.my_icon);
 

I'm currently implementing theme support for my application and a part of it is changing the action bar app icon. I want to use a dark icon when Holo Light is selected. Everything is done in the method except for the part where the action bar app icon is set. The code that im trying to use is:

getActionBar();
ActionBar.setIcon(R.drawable.my_icon);

"There is no such reference avavible here" is the error that i'm getting. How should this be done correctly?

BTW my minSdkVersion is 14 so no action bar sherlock stuff.

getActionBar();

You're throwing the action bar away right there. getActionBar() returns an instance of ActionBar, which you then need to call setIcon() on. Like so:

ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.my_icon);