我正在嘗試制作一個底部導航欄,其中中間的圖示是我自己的圖示,它應該是可點擊的并且應該像這樣適合
在選單目錄中,我創建了bottom_navigation.xml,其中負責我想要的圖示的行是:
<item
android:id="@ id/park"
android:icon="@drawable/ic_parkcenter"
android:title="Park here"/>
在我的 maps_activity.xml(我想要顯示的主頁)中,我使用了這個:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_height="75dp"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:id="@ id/bottom_nav"
map:menu="@menu/bottom_navigation" />
這是我得到的結果
我想把它作為影像視圖而不是一個專案,但遺憾的是它在選單中不起作用。我應該如何繼續這里?提前致謝!
編輯:我的 acitivty_maps.xml,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@ id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Can be ignored -->
<fragment
android:id="@ id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<!-- Can be ignored -->
<androidx.appcompat.widget.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/purple_500"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
map:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottom_nav_left"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_gravity="bottom"
map:menu="@menu/bottom_navigation"
android:background="@color/purple_500"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom">
<!-- For the image i want in the middle -->
<ImageView
android:id="@ id/parkcenter"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@drawable/ic_parkcenter" />
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/bottom_nav_right"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_gravity="bottom"
map:menu="@menu/bottom_navigation"
android:background="@color/purple_500"/>
<!-- Can be ignored -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/parking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center"
android:layout_margin="16dp"
android:contentDescription="@string/parking"
android:src="@drawable/ic_parking" />
</FrameLayout>
</LinearLayout>
如果有幫助,這就是抽屜布局內的全部內容!再次非常感謝!
uj5u.com熱心網友回復:
只需在您的活動或片段中嘗試此 java 代碼:
bottomNavigationView.setItemIconTintList(null) ;
使用bottomNavigationView.
uj5u.com熱心網友回復:
可能有更好的方法來做到這一點,但是實作這樣的事情的一種hacky方法是
<LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_height="75dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:id="@ id/bottom_nav_left"
map:menu="@menu/bottom_navigation" />
<LinearLayout
android:layout_height="100dp"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView
android:layout_height="100dp"
android:layout_width="100dp"
src = ... />
//Add textview or any other view. Otherwise remove linearlayout
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_height="75dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:id="@ id/bottom_nav_right"
map:menu="@menu/bottom_navigation" />
</LinearLayout>
這將在顯示影像時為您提供額外的靈活性(使中間影像變大而底部導航不帶色調)。對于底部導航左側填充帶有影像左側圖示的專案,底部導航右側填充相同
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/373530.html
