[英]Android Eclipse Action Bar Background Image
我想將自己的圖像背景添加到操作欄中。 我怎樣才能做到這一點? 另外,我想在左邊的頂部添加包含文本的我自己的另一個圖像。 這可能嗎?
我根本沒有找到任何例子。
我在values文件夾中有一個“ styles.xml” ,其中包含實際的背景圖像:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Holo" />
<style name="ActionBar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">45dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@drawable/actionbar_bg</item>
</style>
</resources>
在布局文件夾中還包含一個“ actionbarbg.xml” ,其中包含我提到的文本圖像:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ActionBar" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:paddingLeft="15dip"
android:scaleType="center"
android:src="@drawable/bannerlogo" />
/>
</LinearLayout>
我在菜單文件夾中有一個“ actionbar.xml” ,該文件夾在操作欄上包含2個菜單按鈕。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item_refresh"
android:icon="@drawable/help"
android:title="Refresh"
android:showAsAction="ifRoom|withText" />
<item
android:id="@+id/item_save"
android:icon="@drawable/info"
android:title="Save"
android:showAsAction="ifRoom|withText" />
</menu>
我在主類中的代碼:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.actionbarbg, null);
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
結果看起來像這樣:
您使用的是Android 4.0或更高版本嗎? 另外,也許使用福爾摩斯動作欄更容易
也許您可以根據需要嘗試設置android:src和android:background。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.