在MultiAutoCompleteTextView上应用样式 [英] Apply a style on MultiAutoCompleteTextView

查看:83
本文介绍了在MultiAutoCompleteTextView上应用样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MultiAutocompleteTextView上应用一种样式,但是该样式似乎没有被应用.

I am trying to apply a style on the MultiAutocompleteTextView but the style does not seem to be applied.

在style.xml中,我有以下内容(仅显示了一部分):

In style.xml I have following (showing just a portion):

<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>`

在我的布局文件中,我有以下内容:

And in my layout file I have following:

<MultiAutoCompleteTextView
    android:id="@+id/multiAutoCompleteTextView1"
    android:visibility="gone" />

由于主题已应用于整个应用程序,因此也应将其应用于MultiAutocompleteTextView.但是,当我尝试执行该应用程序时,出现以下错误:

Since the theme is applied on the whole application, it should be applied to the MultiAutocompleteTextView as well. But when I try to execute the application I get the following error:

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.

推荐答案

重写主题或样式时,只能重写样式声明的指定属性. 未在Widget.AutoCompleteTextView中声明layout_ * attr,应将layout_ *放置在指定的视图中

When you rewrite a theme or a style,you are only able to rewrite the specify attrs that the style declares. layout_* attr not declared in Widget.AutoCompleteTextView,you should place layout_* for your specify view

这篇关于在MultiAutoCompleteTextView上应用样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆