[英]How to change the icon color selected on bottom navigation bar in android studio
[英]Change alignment of icon and text in custom bottom navigation bar in android
我正在為自定義BottomNavigation欄使用“ com.luseen.spacenavigation.SpaceNavigationView”。 它工作正常,但我的問題是底部導航欄中的圖標和文本對齊。 它水平對齊,但我希望文本在圖標下方對齊。 如何更改對齊方式?
我的XML
<com.luseen.spacenavigation.SpaceNavigationView
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
app:active_item_color="@color/colorAccent"
app:centre_button_color="@android:color/holo_green_light"
app:inactive_item_color="@android:color/darker_gray"
app:space_background_color="@android:color/holo_green_light"
app:centre_button_icon="@drawable/img1"
app:space_item_icon_size="@dimen/space_item_icon_default_size"
app:space_item_icon_only_size="@dimen/space_item_icon_only_size"
app:space_item_text_size="@dimen/space_item_text_default_size"
app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior"/>
在我的活動中
spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space);
spaceNavigationView.initWithSaveInstanceState(savedInstanceState);
spaceNavigationView.addSpaceItem(new SpaceItem("Home", R.drawable.account));
spaceNavigationView.addSpaceItem(new SpaceItem("Help", R.drawable.ic_home_black_24dp));
spaceNavigationView.addSpaceItem(new SpaceItem("Bookings", R.drawable.ic_dashboard_black_24dp));
spaceNavigationView.addSpaceItem(new SpaceItem("Settings", R.drawable.ic_notifications_black_24dp));
spaceNavigationView.shouldShowFullBadgeText(true);
spaceNavigationView.setCentreButtonIconColorFilterEnabled(false);
spaceNavigationView.setSpaceBackgroundColor(Color.WHITE);
spaceNavigationView.setBackgroundColor(Color.GREEN);
您必須在庫內部編輯space_item_view.xml
布局文件才能解決此問題。
space_item_view.xml
<RelativeLayout
android:id="@+id/main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<ImageView
android:id="@+id/space_icon"
android:layout_width="@dimen/space_item_icon_default_size"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_height="@dimen/space_item_icon_default_size" />
<TextView
android:id="@+id/space_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:lines="1"
android:layout_centerHorizontal="true"
android:layout_below="@+id/space_icon"
android:gravity="center"
android:textSize="@dimen/space_item_text_default_size"
tools:text="Label One" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/badge_container"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/badge_left_margin"
android:layout_marginRight="2dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="@+id/main_content"
android:visibility="gone">
<TextView
android:id="@+id/badge_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
轉到SpaceNavigationView.java
類並僅對其進行修改。
public void showIconOnly(boolean value) {
isIconOnlyMode = value;
}
在要實現此功能的活動/片段中,只需替換此spaceNavigationView.showIconOnly();
到spaceNavigationView.showIconOnly(false);
在此回復中找到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.