[英]EditText gets wider when a background color is set
我為EditText設置了黃色背景顏色:
...
<EditText
android:id="@+id/identification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"
style="@style/required" // here I set the background color
>
<requestFocus />
</EditText> ...
風格的XML:
<style name="required">
<item name="android:background">@color/required</item> // #FF9
</style>
問題是在運行時EditText的寬度更大,就像使用橙色邊框選擇它一樣:
那么如何使其寬度與其他EditText的寬度相同?
嘗試這個:
int width = mEditText.getWidth();
mEditText.setMaxWidth(width);
為了檢查EditText的大小,請嘗試使用uiautomatorviewer並檢查它們的大小是否不同。
在您的樣式中,您沒有設置邊距和填充的值。 為其添加父樣式,因此它繼承了布局屬性的默認值:
<style name="required" parent="@android:style/Widget.EditText">
<item name="android:background">@color/required</item>
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.