我在UI中有底欄的標籤佈局。我想選擇一個默認選項卡,但不是底部欄。但在我的代碼中,它們都是同時選中的。任何人都可以請告訴我如何解決這個問題?如何創建沒有默認欄的底欄?
0
A
回答
0
你可以做的工作,如果你身邊喜歡
在您添加一個虛擬項目菜單XML
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/none"
android:title="" /> //add this dummy item and set this selected when your view is created
<item
android:id="@+id/bottomBarItemOne"
android:icon="@drawable/ic_recents"
android:title="Recents" />
<item
android:id="@+id/bottomBarItemtwo"
android:icon="@drawable/ic_map"
android:title="Map" />
<item
android:id="@+id/bottomBarItemthree"
android:icon="@drawable/ic_view"
android:title="View" />
</menu>
添加您的菜單在活動
public class MainActivity extends AppCompatActivity {
private BottomBar mBottomBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItemsFromMenu(R.menu.menu, new OnMenuTabSelectedListener() {
@Override
public void onMenuItemSelected(int resId) {
if (resId == R.id.bottomBarItemOne) {
// the user selected item number one
}else if(resId == R.id.bottomBarItemtwo){
}
}
});
mBottomBar.setDefaultTabPosition(1);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Necessary to restore the BottomBar's state, otherwise we would
// lose the current tab on orientation change.
mBottomBar.onSaveInstanceState(outState);
}
}
+0
即時錯誤setDefaultTabPosition(0); –
+0
不好意思把它改成setDefaultTabPosition(1); – SaravInfern
相關問題
- 1. 創建底部導航欄
- 2. 如何在DHTMLX中創建底部工具欄(狀態欄)?
- 3. 安卓底部欄設置默認選項卡上創建的活動
- 4. 如何在底部設置android默認標題欄和圖像?
- 5. 如何在android模擬器底部創建沒有系統欄的屏幕?
- 6. Android的工作室 - 創建底欄
- 7. 如何申請欄默認在SQLAlchemy的
- 8. 如何在Java應用程序的底部創建一個欄,如狀態欄?
- 9. 如何在jQuery Mobile默認導航欄中擁有更大的中心底部導航欄按鈕?
- 10. jQuery彈出欄 - 如何隱藏默認?
- 11. 如何覆蓋「默認」導航欄?
- 12. 如何編輯默認導航欄?
- 13. 有沒有辦法替換默認的X11菜單欄?
- 14. 如何爲沒有側邊欄的主題創建窗口化邊欄?
- 15. 工具欄與類「工具欄底」創建頁面內容
- 16. 創建工具欄菜單與底部欄
- 17. 如何創建沒有任何窗口的任務欄按鈕?
- 18. 如何將div欄放在我的側欄欄底部?
- 19. 如何創建類似於instagram的底部導航欄
- 20. 如何將動態創建的操作欄設置爲底部?
- 21. 如何創建範圍欄?
- 22. 如何創建選項欄
- 23. 刪除默認標題欄
- 24. 默認導航欄顏色
- 25. SSRS默認標題欄
- 26. 如何在默認的Google主頁上創建菜單「工具欄」?
- 27. 如何創建自定義標籤欄,無需默認選擇任何項目
- 28. 帶有底欄的窗口
- 29. 如何使欄PriceGrabber.com底部
- 30. 如何在頁面底部創建碼頭類型工具欄?
包括足夠的代碼讓別人重現問題。有關這方面的幫助,請閱讀http://stackoverflow.com/help/mcve – zajonc