有没有一种方法来设置动作条backgound由图像中的android?方法来、图像、动作、backgound

2023-09-12 01:54:47 作者:陪你短衣到长裙落地

我需要改变操作栏的背景,自定义图像,但每一次我尝试使用这个code它不会改变任何事情。

 位图B = BitmapFactory.de codeResource(getResources(),R.drawable.navbarbg);
BitmapDrawable BD =新BitmapDrawable(getResources(),B);
bar.setBackgroundDrawable(BD);
 

另外我想这code,但没有奏效。

 资源资源= getResources();
XPP = res.getXml(R.drawable.actionbar_background);
bitmapDrawable =(BitmapDrawable)BitmapDrawable.createFromXml(RES,XPP);
 

actionbar_background.xml的内容

 < XML版本=1.0编码=UTF-8&GT?;
<位图的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:SRC =@可绘制/ navbarbg
机器人:TILEMODE =重复/>
 
CAD里面的图层设置怎么保存

编辑: 我用这罚款这个工作code:

 位图BMAP = BitmapFactory.de codeResource(RES,R.drawable.action_bar_bg);
BitmapDrawable actionBarBackground =新BitmapDrawable(RES,BMAP);
动作条酒吧= getActionBar();
bar.setBackgroundDrawable(actionBarBackground);
 

解决方案

我用这罚款这个工作code:

 位图BMAP = BitmapFactory.de codeResource(RES,R.drawable.action_bar_bg);
BitmapDrawable actionBarBackground =新BitmapDrawable(RES,BMAP);
动作条酒吧= getActionBar();
bar.setBackgroundDrawable(actionBarBackground);
 

I need to change background of the action bar to a customized image, but every time I try to use this code it does not change a thing.

Bitmap b =  BitmapFactory.decodeResource(getResources(), R.drawable.navbarbg);
BitmapDrawable bd = new BitmapDrawable(getResources(), b);
bar.setBackgroundDrawable(bd);

Also I tried this code but it didn't work.

Resources res = getResources();
xpp =res.getXml(R.drawable.actionbar_background);
bitmapDrawable = (BitmapDrawable) BitmapDrawable.createFromXml (res, xpp);

The contents of actionbar_background.xml are

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/navbarbg"
android:tileMode="repeat" />

Edited: I used this code which worked fine:

Bitmap bMap = BitmapFactory.decodeResource(res, R.drawable.action_bar_bg);
BitmapDrawable actionBarBackground = new BitmapDrawable(res, bMap);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(actionBarBackground);

解决方案

I used this code which worked fine:

Bitmap bMap = BitmapFactory.decodeResource(res, R.drawable.action_bar_bg);
BitmapDrawable actionBarBackground = new BitmapDrawable(res, bMap);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(actionBarBackground);

 
精彩推荐
图片推荐