我試圖做一個底部導航欄改變基於按鈕上的活動,但每當我試圖教程有一個錯誤或其他創建底部導航欄
創建底部導航欄
回答
你可以使用這個庫bottomnavifationbar
github lib, github lib 2, githublib 3, github lib 4,
或 試試這個
complie這depedencie
compile ‘com.android.support:design:25.3.1’
創建這樣
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Content Container -->
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
佈局創建菜單,按您的reqirement
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorites"
android:enabled="true"
android:icon="@drawable/ic_favorite_white_24dp"
android:title="@string/text_favorites"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:enabled="true"
android:icon="@drawable/ic_access_time_white_24dp"
android:title="@string/text_schedules"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:enabled="true"
android:icon="@drawable/ic_audiotrack_white_24dp"
android:title="@string/text_music"
app:showAsAction="ifRoom" />
**Handling Enabled/Disabled states. Make selector file.**
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_enabled="true" />
<item android:color="@color/colorPrimaryDark" android:state_enabled="false" />
</selector>
個
手柄click事件
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_favorites:
break;
case R.id.action_schedules:
break;
case R.id.action_music:
break;
}
return false;
}
});
官方不再支持,這樣你就可以請嘗試radiobutton和viewpager。
錯誤信息:https://developer.android.com/reference/android/support/design/widget/BottomNavigationView .html – reTs
我明白了,非常感謝您的建議,並希望能與您進一步溝通。 –
我認爲,如果你想要的東西作爲導航欄你應該嘗試,因爲有許多偉大的事情有喜歡把自己到GitHub上: https://github.com/Nightonke/BoomMenu
試試吧,看起來方式比簡單的導航欄更好。 歡呼
- 1. jQuery Mobile底部導航欄
- 2. 導航欄飛到底部
- 3. 缺少導航欄和底部欄
- 4. 如何創建類似於instagram的底部導航欄
- 5. 如何創建底部導航
- 6. 導航欄狀態,顯示和隱藏底部導航欄
- 7. 的Android - 導航欄取代我的底部導航欄
- 8. Bootstrap:在導航欄固定頂部和導航欄固定底部之間創建一個動態div
- 9. 導航控制器底部欄
- 10. 導航欄顯示在底部
- 11. 導航欄在底部居中 - CSS
- 12. jQuery Mobile的導航欄底部
- 13. 導航欄隱藏NestedScrollView的底部[Android]
- 14. 塑造導航欄的底部邊框
- 15. Appcelerator Android新底部導航欄
- 16. Highcharts,放大底部導航欄
- 17. Bootstrap底部滾動導航欄
- 18. Android底部導航欄帶陰影
- 19. 桌面導航欄粘頂部粘底
- 20. 隱藏底部導航欄 - 在底部顯示白色條
- 21. 創建滾動導航欄
- 22. 導航欄創建錯誤
- 23. 動態創建導航欄
- 24. 創建2級導航欄
- 25. Android - 底部導航視圖和導航欄內的片段
- 26. Android底部導航
- 27. 改變導航欄-固定頂部導航欄靜態頂創建上述頭
- 28. 側欄導航改爲導航欄中的頂部導航欄
- 29. Angular4-Bootstrap4:從導航欄創建subnav欄
- 30. 如何刪除導航欄項目和導航欄底部之間的間隙?
的Android工作室(2.3)最有可能是沒有問題的。請發佈您的錯誤 –
您收到了哪些錯誤? – Abhi
嗨,我認爲使用底部導航欄來改變活動將是壞主意,改爲使用片段。您可以嘗試android studio中底部導航的活動模板。 –