【问题标题】:Setting a style on an individual view does not work在单个视图上设置样式不起作用
【发布时间】:2013-01-24 20:25:57
【问题描述】:

我在我的一项活动中为个人视图设置主题时遇到问题。

在我的清单中的应用程序标签中设置主题非常有效,就像在清单中的活动标签中设置主题一样。

无论我是否在清单中设置了主题,如果我尝试在单个视图上设置主题:

<TextView
        android:id="@+id/userFullNameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/profileImageView"
        android:text="Bobby Joe"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:theme="@style/Theme.Sherlock.Light" />

视图始终以默认主题(清单中未设置任何内容)或清单中指定的相同主题显示。

我不会在我的 xml 文件中的任何地方覆盖 Theme.Sherlock.Light 主题。我尝试了几种不同的主题组合,但无济于事。哦,我显然在使用 ActionBarSherlock。

编辑

如果我创建一个新样式:

<style name="SideMenuStyle" parent="Theme.Sherlock.Light" >
</style>

并在我的 xml 中使用此样式,它仍然无法显示正确的样式。

【问题讨论】:

    标签: android actionbarsherlock android-theme


    【解决方案1】:

    没有为视图定义android:theme xml 属性。您可以改用style xml 属性,但您必须引用视图的样式而不是整个主题。 像这样使用它:

    <TextView
        android:id="@+id/userFullNameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/profileImageView"
        android:text="Bobby Joe"
        android:textAppearance="?android:attr/textAppearanceMedium"
        style="@style/MyTextViewStyle" />
    

    请注意,您还可以为TextView 的所有实例或主题范围内的任何其他小部件定义默认主题。对于TextView,这意味着在主题中定义android:textViewStyle

    <style name="MyTheme" parent="@style/Theme.Sherlock">
        <item name="android:textViewStyle">@style/MyTextViewStyle</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 2010-11-13
      • 2018-01-15
      • 2017-06-25
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      相关资源
      最近更新 更多