How to center&left&right align the ActionBar icons in Android

后端 未结 1 687
孤独总比滥情好
孤独总比滥情好 2021-01-17 16:57

hi there I want align a set of icons in toolbar like below picture.

I googled and after some change I have:

mainActivity.xml

...



        
相关标签:
1条回答
  • 2021-01-17 17:43

    This answer might be a bit late. However, using today's current material components library you can use a bottom app bar to achieve your desired result. See pseudo code snippet:

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:backgroundTint="@color/colorBottomBar"
            app:fabAlignmentMode="center"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
    
                <TextView
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1
                    android:drawableTop="@drawable/ic_blur"
                    android:gravity="center"
    
                </TextView>
            </LinearLayout>
        </com.google.android.material.bottomappbar.BottomAppBar>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    android:drawableTop="@drawable/ic_blur" would be used to represent the icons that you want to have displayed in the bottom app bar.

    You would have to import the material components library for you to use the bottom app bar

    0 讨论(0)
提交回复
热议问题