Android 如何基于string.xml值更改操作栏样式
我需要根据对strings.xml文件所做的一些更改来更改操作栏 在strings.xml中Android 如何基于string.xml值更改操作栏样式,android,xml,Android,Xml,我需要根据对strings.xml文件所做的一些更改来更改操作栏 在strings.xml中 <string name="app_url">http://example.com</string> http://example.com 若我硬编码到新的url,那个么ActionBar应该是不同的 <string name="app_url">http://temparary.com</string> http://temparary.com
<string name="app_url">http://example.com</string>
http://example.com
若我硬编码到新的url,那个么ActionBar应该是不同的
<string name="app_url">http://temparary.com</string>
http://temparary.com
有没有办法改变我的类的oncreate方法中的操作栏样式。试试这个
onCreate获取字符串应用程序url中的第一个
String str = getString(R.string.app_url);
ActionBar actionbar = getActionBar();
if(str.equalsIgnoreCase("link1")) {
//style your actionbar according to link1
} else {
//style your actionbar according to link2
}
编辑
要在Actionbar上添加sprite,您可以创建一个9补丁图像,并将该图像设置为Actionbar的背景图
像
你能给样式操作栏添加一个代码吗。我需要在actionbar上添加条纹。检查这个
Drawable res = getResources().getDrawable(R.drawable.your_image);
getActionBar().setBackgroundDrawable(res);