Here are sample pictures of two EditText
fields I've added in an Action Bar:
[This is from the Graphical Layout tool in Eclipse]
[This is what it looks like in my emulator (2.1 WVGA854)
My question is, how can I make the EditText
look a bit closer to the Graphical Layout? Or is this a function of the emulation? On my device, which has a custom rom, the EditText
is square but looks similar to the Graphical Layout, which is what I want.
I've tried setting the textAppearance to "@android:attr/textAppearanceSmall"
. This does help in that it changes the size of the text within the EditText to be viewable, but it does not affect the size of the EditText
itself.
Here's the XML for my EditText:
<EditText
android:maxLines="1"
android:scrollHorizontally="true"
android:textAppearance="@android:attr/textAppearanceSmall"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
I could post the full XML, but essentially this EditText is enclosed (along with the search icon ImageView) in a RelativeLayout that is within another RelativeLayout.
Thanks for any he开发者_如何转开发lp!
EDIT By request, here is the full XML for the top search bar:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/IBSearchOverlayMic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/aslctr_search_overlay_blackbutton"
android:src="@drawable/search_overlay_ic_microphone" />
<ImageView
android:id="@+id/IVSearchOverlayDivider1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/IBSearchOverlayMic"
android:src="@drawable/search_overlay_division" />
<ImageButton
android:id="@+id/IBSearchOverlaySearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/IVSearchOverlayDivider1"
android:background="@drawable/aslctr_search_overlay_blackbutton"
android:src="@drawable/search_overlay_ic_searchwhite" />
<RelativeLayout
android:id="@+id/RLSearchOverlaySearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/IBSearchOverlaySearch"
android:layout_alignBottom="@id/IBSearchOverlaySearch"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/IBSearchOverlaySearch"
android:layout_centerVertical="true"
android:background="@drawable/search_overlay_searchbg">
<EditText
android:id="@+id/ETSearchOverlaySearch"
android:maxLines="1"
android:scrollHorizontally="true"
android:textAppearance="@android:attr/textAppearanceSmall"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/ETSearchOverlaySearch"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:clickable="false"
android:focusable="false"
android:src="@drawable/search_actionbar_ic_searchcream" />
</RelativeLayout>
</RelativeLayout>
I determined the problem. The issue was that the EditText was inside the RelativeLayout...I think that messed with the padding, or perhaps the EditText's layout_height="wrap_content" meant that it extended vertically. Here's the reworked XML:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/IBSearchOverlayMic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/aslctr_search_overlay_blackbutton"
android:src="@drawable/search_overlay_ic_microphone" />
<ImageView
android:id="@+id/IVSearchOverlayDivider1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/IBSearchOverlayMic"
android:src="@drawable/search_overlay_division" />
<ImageButton
android:id="@+id/IBSearchOverlaySearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/IVSearchOverlayDivider1"
android:background="@drawable/aslctr_search_overlay_blackbutton"
android:src="@drawable/search_overlay_ic_searchwhite" />
<ImageView
android:id="@+id/IVSearchBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/IBSearchOverlaySearch"
android:layout_alignBottom="@id/IBSearchOverlaySearch"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/IBSearchOverlaySearch"
android:layout_centerVertical="true"
android:background="@drawable/search_overlay_searchbg" />
<EditText
android:id="@+id/ETSearchOverlaySearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/IBSearchOverlaySearch"
android:layout_alignBottom="@id/IBSearchOverlaySearch"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/IBSearchOverlaySearch"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginBottom="0dip"
android:paddingBottom="0dip"
android:maxLines="1"
android:scrollHorizontally="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/IBSearchOverlaySearch"
android:layout_alignTop="@id/IBSearchOverlaySearch"
android:layout_alignBottom="@id/IBSearchOverlaySearch"
android:layout_centerVertical="true"
android:layout_marginRight="15dip"
android:clickable="false"
android:focusable="false"
android:src="@drawable/search_actionbar_ic_searchcream" />
</RelativeLayout>
精彩评论