简体   繁体   中英

How do I stretch an EditText to entire phone's width and leave a space for 1 button?

I am trying to stretch the EditText (on ActionBar) to "almost" entire screen's width.It should first leave space for a button to the right then the rest is EditText's pace. I can put about 300dp which could make it seem nice on my phone but it's not a preferable solution.

My code: action_menu

<item
    android:id="@+id/action_settings"
    android:actionLayout="@layout/action_item_edit_text"
    android:showAsAction="always"
    android:title="Search"/>
<item
    android:id="@+id/add"
    android:icon="@drawable/add"
    android:showAsAction="always"
    android:title="Add"/>

<!-- Settings, should always be in the overflow -->

action_item_edit_text

<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:hint="Write something"
android:padding="6dp"
android:singleLine="true"
android:textColor="@android:color/black"
android:textColorHint="#BBBBBB"
android:textSize="14sp" />    
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button 
        android:id="@+id/button"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

    <EditText
        android:layout_toLeftOf="@id/button"
        android:layout_alignParentLeft="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

Something like that. I haven't tested this I just wrote it blindly, but the concept is sound.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM