2015-02-10 20 views
0

的目標是在顯示操作欄編輯文本拉伸到屏幕的端部:ActionBar:如何拉伸動作視圖佈局?

enter image description here

但結果是,動作視圖佈局看起來包裹: enter image description here

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:background="@android:color/darker_gray" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize"> 

     </android.support.v7.widget.Toolbar> 

</LinearLayout> 

bar_search.xml

<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

menu_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item 
     android:id="@+id/action_search" 
     android:icon="@android:drawable/ic_menu_search" 
     android:title="search" 
     app:actionLayout="@layout/bar_search" 
     app:showAsAction="ifRoom|collapseActionView" /> 
</menu> 

謝謝!

+0

這並不完全清楚你期待什麼結果,以及你目前的結果有什麼問題。你能否詳細說明一下? – 2015-02-10 11:01:19

+0

我更新了我的問題 – Sinigami 2015-02-10 13:29:28

+1

您是否嘗試將EditText放在LinearLayout或RelativeLayout中? – 2015-02-10 13:33:18

回答

1

當涉及到ActionView時,ActionBar可能會有點奇怪。對於比圖標稍微複雜的視圖,將所有UI元素包裝在ViewGroup之內是很好的做法。

大多數時間LinearLayoutRelativeLayout做的伎倆。嘗試在RelativeLayout內包裝EditText