操作欄我要實現像上的圖片底部的一個我自己的Android應用程序的操作欄。 我搜索了很多,但出現了很多錯誤。
我嘗試了一些圖書館的幫助,例如:Greendroid和ActionBarSherlock,但它們都沒有工作,或者我無法完美地使用它們! ..
我真的需要在我的應用程序中的操作欄。
如果有人能幫助我一些樣品或代碼或向我解釋,我將不勝感激。
感謝很多:) ..
操作欄我要實現像上的圖片底部的一個我自己的Android應用程序的操作欄。 我搜索了很多,但出現了很多錯誤。
我嘗試了一些圖書館的幫助,例如:Greendroid和ActionBarSherlock,但它們都沒有工作,或者我無法完美地使用它們! ..
我真的需要在我的應用程序中的操作欄。
如果有人能幫助我一些樣品或代碼或向我解釋,我將不勝感激。
感謝很多:) ..
您可以使用SplitActionBar。您的應用程序支持在Android 4.0(API級別14)或更高版本上運行
修復方法是始終在頂部欄中有一個項目,以防止底部內容永遠無法安裝在此處,從而強制所有內容進入底部欄。從另一個用戶看看這個示例項目:
<?xml version="1.0" encoding="utf-8"?
<manifest package="com.commonsware.android.actionbarbc"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:hardwareAccelerated="true"
android:icon="@drawable/cw"
android:label="@string/app_name">
<activity android:label="@string/app_name"
android:name=".InflationDemo"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
</manifest>
他用此代碼爲他的活動:
private void setupActionBar() {
ActionBar actionBar = getActionBar();
ViewGroup v = (ViewGroup)LayoutInflater.from(this)
.inflate(R.layout.conversation_list_actionbar, null);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(v,
new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.RIGHT));
mUnreadConvCount = (TextView)v.findViewById(R.id.unread_conv_count);
}
http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
我想你需要看的東西叫做SplitActionBar。
此文檔是here。
從簡要介紹一下,它僅適用於「窄」屏幕,並且您聲明要通過將uiOptions="splitActionBarWhenNarrow"
添加到AndroidManifest.xml文件的or元素中來使用拆分操作欄。
您可能會強制它始終顯示,但我不知道,因爲我以前沒有使用它。
我希望這會有所幫助。
我開始閱讀它,但我找不到任何示例代碼來完美應用,你可以幫我嗎? – Adly
檢查以前的答案 – StuStirling
我成功了,但有一件事是你說的,當我添加菜單中的5個元素,操作欄只顯示3個元素,並不像上面的圖片那麼你認爲問題怎麼樣? 我把你說的有關:splitactionbarwhennarow,但仍然不工作..? – Adly
「但是出現了很多錯誤。」在使用uiOptions =「splitActionBarWhenNarrow」時是否有任何錯誤? –
否不在該行中,另一個用於style.xml文件上的「WindowsTitleBackground」! ..我讀了關於splitactionbarwhenNarrow,但我不能應用它,因爲錯誤:( – Adly
什麼錯誤?... –