Android ActionBar custom layout styling

后端 未结 3 742
灰色年华
灰色年华 2020-12-14 20:05

I\'m just starting android development coming from IOS and again stubbled onto a problem. And after 1 day of trying i decided that i will ask the people of stack overflow.

相关标签:
3条回答
  • 2020-12-14 20:32

    you're not getting your result because:

    enter image description here

    u need to:

    1. if you use AppCompat theme

    enter image description here

    1. add to your activity layout

    enter image description here

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

    enter image description here

    0 讨论(0)
  • 2020-12-14 20:40

    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?

    0 讨论(0)
  • 2020-12-14 20:41

    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>
    
    0 讨论(0)
提交回复
热议问题