1

I have few elements within the toolbar in this order:

<android.support.v7.widget.Toolbar>
 <ImageButton android:layout_width="48dp"/>

     <EditText android:layout_width = "fill_parent"/>

 <Button android:layout_width="48dp"/>
<Button android:layout_width="24dp"/> 
</android.support.v7.widget.Toolbar>

But when I change this EditText to fill_parent I don't see these two buttons after that. So my guess is that I'm doing something wrong, but don't know what.

ShP
  • 1,143
  • 1
  • 12
  • 41
  • I don't think you are using Toolbar quite the way it's intended. See: http://stackoverflow.com/questions/26778701/how-to-add-buttons-like-refresh-search-in-toolbar-in-android – emerssso Nov 10 '15 at 00:55
  • How's that? I can use menu.xml with Items inside, but because I don't want to use search widget instead of edittext and because I want to be more flexible with UI I can also use it that way. But anyway, that's not the answer to my question :) – ShP Nov 10 '15 at 00:57

1 Answers1

0

I guess you need something like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="48dp"
            android:layout_height="match_parent"
            android:layout_centerVertical="true" />

        <Button
            android:id="@+id/button2"
            android:layout_width="24dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />

        <Button
            android:id="@+id/button1"
            android:layout_width="48dp"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@id/button2" />

        <EditText
            android:layout_toRightOf="@id/imageButton"
            android:layout_toLeftOf="@id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>
</android.support.v7.widget.Toolbar>

And fill_parent is depricated, use match_parent instead

Igor Tyulkanov
  • 5,487
  • 2
  • 32
  • 49
  • I used your example, but for some reason in my case EditText is then over these ImageButton and over these two buttons. However I managed to solve that by setting up margin left and right (because I know exact size of my buttons and margins between them), so I achieved wanted look, but I guess that's not the best solution. – ShP Nov 10 '15 at 01:49
  • I will accept your answer anyway, but if you can think of what can be the reason for that I would really appreciate. – ShP Nov 10 '15 at 01:49
  • You can post your edited code and maybe sketch you want to do. I'll try to help – Igor Tyulkanov Nov 10 '15 at 02:26
  • The code is exactly the same as above for example and this is what I want to achieve http://prntscr.com/8zdvy8 and so far I managed to create everything except this button to stick out of toolbar even with android:clipChildren="false" and android:clipToPadding="false" on parents and negative margin bottom on button itself – ShP Nov 10 '15 at 02:29
  • I managed to create everything except this button to have z-index higher than element bellow so it looks like it's still in the toolbar even with clip children = false and in reality is just under the view bellow (outside the toolbar). – ShP Nov 10 '15 at 02:44