我正在尝试在MultiAutocompleteTextView上应用样式,但似乎没有应用样式。
在style.xml中,我有以下内容(仅显示部分内容):
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:buttonStyle">@style/Button</item>
<item name="android:imageButtonStyle">@style/ImageButton</item>
<item name="android:editTextStyle">@style/Edit</item>
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextView</item>
<!-- In the line above I tried to set "android:multiAutoCompleteTextViewStyle" but that doesn't seem to work. My guess is that it is because MultiAutoCompleteTextView is a subclass of AutoCompleteTextView -->
</style>
...
<style name="AutoCompleteTextView" parent="@android:style/Widget.AutoCompleteTextView">
<item name="android:completionHintView">@layout/completion_hint</item>
<item name="android:background">@drawable/edit</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:ems">10</item>
<item name="android:gravity">top</item>
<item name="android:lines">1</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">@color/black</item>
</style>`
在我的布局文件中,我有以下内容:
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView1"
android:visibility="gone" />
由于主题应用于整个应用程序,因此它也应该应用于MultiAutocompleteTextView。但是当我尝试执行应用程序时,我收到以下错误:
12-03 02:00:34.398: E/AndroidRuntime(591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MyActivity}: java.lang.RuntimeException: Binary XML file line #37: You must supply a layout_width attribute.
答案 0 :(得分:0)
当您重写主题或样式时,您只能重写样式声明的指定attrs。 layout_ * attr未在Widget.AutoCompleteTextView中声明,您应该为指定视图放置layout_ *