It's beautiful to put in a toolbar image button.



  • I have a layout toolbar, there are certain elements, when the button is added, these elements are moving.

    I need to tie this button to the right side of the bar. How to do that without changing elements.

    Marking code:

    <RelativeLayout
        android:id="@+id/autocode_layout_mainToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingRight="24dp"
            android:src="@drawable/logo" />
    
    &lt;ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" /&gt;
    

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/title_layout_mainToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
    android:id="@+id/cancel_button_toolbar"
    style="@style/Widget.AppCompat.Button.Borderless"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:visibility="gone"
    android:fontFamily="sans-serif-medium"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:text="@string/cancel" />

    &lt;TextView
        android:id="@+id/title_textView_mainToolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true" /&gt;
    
    &lt;LinearLayout
        android:id="@+id/autoExpert_layout_mainToolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:paddingRight="24dp"
        android:layout_toLeftOf="@+id/done_button_toolbar"
        android:layout_toStartOf="@+id/done_button_toolbar"
        android:orientation="horizontal"
        android:layout_below="@id/imageView2"&gt;
    
        &lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:textColor="@color/text_in_list"
            android:fontFamily="sans-serif-light"
            android:textSize="22sp"
            android:text="@string/auto"/&gt;
    
        &lt;TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/text_in_list"
            android:fontFamily="sans-serif-medium"
            android:textSize="22sp"
            android:text="@string/expert"/&gt;
    
    
    
        &lt;ImageView
            android:layout_width="17dp"
            android:layout_height="17dp"
            android:src="@drawable/check"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/layout"
            android:layout_toEndOf="@+id/layout" /&gt;
    
        &lt;ImageButton
            android:id="@+id/light_button"
            android:layout_width="50dp"
            android:src="@drawable/lightning"
            android:background="@color/white"
            android:layout_height="50dp" /&gt;
    
    &lt;/LinearLayout&gt;
    
    
    &lt;Button
        android:id="@+id/done_button_toolbar"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:textStyle="bold"
        android:fontFamily="sans-serif-medium"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="@string/done" /&gt;
    

    </RelativeLayout>



  • It's part of your version:

    <RelativeLayout android:id="@+id/title_layout_mainToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <Button
        android:id="@+id/cancel_button_toolbar"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:visibility="visible"
        android:fontFamily="sans-serif-medium"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:text="close" />
    

    <TextView
    android:id="@+id/title_textView_mainToolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true" />

    <LinearLayout
    android:id="@+id/autoExpert_layout_mainToolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="visible"
    android:paddingRight="24dp"
    android:layout_toLeftOf="@+id/done_button_toolbar"
    android:layout_toStartOf="@+id/done_button_toolbar"
    android:orientation="horizontal"
    >

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textColor="@color/blue_grey_500"
        android:fontFamily="sans-serif-light"
        android:textSize="22sp"
        android:text="auto"/&gt;
    
    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorGold"
        android:fontFamily="sans-serif-medium"
        android:textSize="22sp"
        android:text="expert"/&gt;
    
    
    
    &lt;ImageView
        android:layout_width="17dp"
        android:layout_height="17dp"
        android:src="@color/colorAccent"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/layout"
        android:layout_toEndOf="@+id/layout" /&gt;
    
    &lt;ImageButton
        android:id="@+id/light_button"
        android:layout_width="50dp"
        android:src="@color/colorGreen"
        android:background="@color/colorBlack"
        android:layout_height="50dp"
        android:layout_gravity="right"/&gt;
    

    </LinearLayout>

    <Button
    android:id="@+id/done_button_toolbar"
    style="@style/Widget.AppCompat.Button.Borderless"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="visible"
    android:textStyle="bold"
    android:fontFamily="sans-serif-medium"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:text="done" />
    </RelativeLayout>

    введите сюда описание изображения

    Green square is an interesting button, if you want to remove that step on your right, you need to change the container to this.

    <LinearLayout
    android:id="@+id/autoExpert_layout_mainToolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="visible"
    android:layout_toLeftOf="@+id/done_button_toolbar"
    android:layout_toStartOf="@+id/done_button_toolbar"
    android:orientation="horizontal"
    >

    If I'm sure you're right,




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2