Android ActionBar custom layout styling

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 01:32:58

try change the root layout into relative layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal">

<TextView
    android:text="left text"
    android:layout_toLeftOf="@+id/icon"
    android:layout_alignParentLeft="true"
    android:id="@+id/text_left"
    android:gravity="left"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"/>

<ImageView
    android:layout_centerHorizontal="true"
    android:id="@+id/icon"
    android:layout_width="10dp"
    android:layout_height="wrap_content"
    android:src="@drawable/bg_sunrise"
    android:layout_gravity="center"/>

<TextView
    android:text="Right txt"
    android:layout_toRightOf="@+id/icon"
    android:id="@+id/text_right"
    android:layout_width="match_parent"
    android:gravity="right"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:paddingRight="5dp"/> </RelativeLayout>

you're not getting your result because:

u need to:

  1. if you use AppCompat theme

  1. add to your activity layout

  1. in code eg. in onCreate() set a toolbar to replace the action bar.

Clocker

You could also use LinearLayout as a root and add android:weightSum and specify a layout_weight on the three child views.

What is android:weightSum in android, and how does it work?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!