主菜单:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gpsproship="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_dieuhuongactivity">
<item android:id="@+id/menu_dieuhuongactivity_search"
android:icon="@drawable/search"
gpsproship:showAsAction="ifRoom|collapseActionView"
gpsproship:actionLayout="@layout/search_layout"/>
</menu>
SearchLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/txt_search"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="number"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
但是当我运行时,edittext id txt_search width not fill ... this ia smaill width
答案 0 :(得分:1)
使用RelativeLayout与我合作
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/visibility_search_edit_text"/>
</RelativeLayout>
答案 1 :(得分:0)
试试这个
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="search_title"
app:actionViewClass="android.support.v7.widget.SearchView"
android:actionLayout="@layout/your_layout_name"
app:showAsAction="collapseActionView|ifRoom" />
不同之处在于showAsAction属性和actionlayout