2015-12-21 69 views
0

我正在使用一個自定義工具欄佈局,其中放置了用於搜索的EditText。文本框被截斷在頂部。請參閱所附的截屏,ToolBar中的自定義TextView被截斷

enter image description here

下面是工具欄的佈局文件。

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/appColor" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Toolbar Title" 
     android:layout_gravity="center" 
     android:textColor="#ffffff" 
     android:textSize="10pt" 
     android:visibility="gone" 
     android:id="@+id/toolbar_title" /> 

     <ImageButton 
      android:id="@+id/btn_MapFlip" 
      android:layout_width="32dp" 
      android:layout_height="28dp" 
      android:tag="0" 
      android:background="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/post_job_slide" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginRight="10dp" 
     /> 
    <RelativeLayout 
     android:id="@+id/layout_Background" 
     android:layout_width="wrap_content" 
     android:layout_height="30dp" 
     android:background="@drawable/search_field"> 
     <EditText android:id="@+id/searchBox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:hint="@string/search_hint" 
      android:inputType="text"> 
      <requestFocus /> 
     </EditText> 
     </RelativeLayout> 


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

爲什麼文本過得好頂部切?這是在工具欄中添加EditText的正確方法嗎?

謝謝。

+1

也許30dp layout_height @ + id/layout_Background是不夠的。 –

回答

0

將相對佈局的高度從30 dp更改爲wrap_content。由於相對佈局的30 dp高度是編輯文本的父級高度,因此您的編輯文字高度也將變爲30dp。

<RelativeLayout 
     android:id="@+id/layout_Background" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/search_field"> 
     <EditText android:id="@+id/searchBox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:hint="@string/search_hint" 
      android:inputType="text"> 
      <requestFocus /> 
     </EditText> 
     </RelativeLayout>