我想將我自己的圖片背景添加到操作欄。我怎樣才能做到這一點?此外,在左邊的這個頂部,我想添加另一個包含文本的圖像。這可能嗎?Android Eclipse Action Bar背景圖片
我還沒有設法找到任何這樣的例子。
我有一個「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及更高版本。 – user1319668 2014-09-26 14:03:56