-6

enter image description here

I need to create Bottom Navigation with two menu item. but the view ratio is 30:70 and text gravity is in centre. one menu contain image and text one is only text

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@+id/bottom_navigation_1"
    android:icon="@drawable/ic_symbol1"
    android:title="@string/bottom_navigation_title1"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/bottom_navigation_2"
    android:icon="@drawable/ic_symbol2"
    android:title="@string/bottom_navigation_title2"
    app:showAsAction="always|withText" />

Below code in main layout

<android.support.design.widget.BottomNavigationView
    android:state_enabled="true"
    android:id="@+id/home_screen_bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/bottom_navigation1" />
Prince Kumar
  • 593
  • 2
  • 7
  • 17

2 Answers2

1

I need to create Bottom Navigation with two menu item. but the view ratio is 30:70 and text gravity is in centre. one menu contain image and text one is only text

AFAIK you can not achieve using menu better to create custom layout for this

Sample code

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_margin="10dp"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/ic_message"
        android:gravity="center"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:background="#24edf1"
        android:text="Message" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".7"
        android:padding="5dp"
        android:textStyle="bold"
        android:textColor="#24edf1"
        android:background="#dedbdb"
        android:gravity="center"
        android:text="BUY" />

</LinearLayout>

OUTPUT

enter image description here

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

You can use simple LinearLayout and weightsum diving your weight with 70-30 to avoid complexity BottomNavigation menu. Set one view with vertical linear layout using ImageView and TextView and another view with only TextView. Parent of both views will be horizontal LinearLayout.

Nir Patel
  • 357
  • 4
  • 17