【问题标题】:Property "android:textSize" not applied when in custom style在自定义样式中未应用属性“android:textSize”
【发布时间】:2014-05-21 01:59:04
【问题描述】:

我有以下布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="10sp"
    android:paddingBottom="10sp">

    <ImageView
        android:id="@+id/newsImage"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:contentDescription="@string/hello_world"
        android:src="@drawable/ic_program_blue" />

    <RelativeLayout 
        android:id="@+id/textLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/newsImage">

        <TextView
            android:id="@+id/titleText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello_world"
            style="@style/newsListItemTitle" />
        <TextView
            android:id="@+id/shortText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/titleText"
            android:text="@string/hello_world" 
            style="@style/newsListItemShort" />

    </RelativeLayout>

</RelativeLayout>

还有这个样式定义:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>


    <!-- NAVIGATION DRAWER -->

    <!-- Items -->
    <style name="navDrawerItem">
        <item name="android:minHeight">48dp</item>
        <item name="android:textSize">22sp</item>
        <item name="android:textColor">#686868</item>
        <item name="android:paddingRight">40dp</item>
        <item name="android:gravity">center_vertical</item>
    </style>


    <!-- NEWS -->

    <!-- Item title -->
    <style name="newsListItemTitle">
        <item name="android:singleLine">true</item>
        <item name="android:background">#66ffffff</item>
        <item name="android:paddingTop">10dp</item>
        <item name="android:paddingLeft">5dp</item>
        <item name="android:textColor">#000000</item>
        <item name="android:textSize">23sp</item>
    </style>

    <!-- Item short -->
    <style name="newsListItemShort">
        <item name="android:singleLine">true</item>
        <item name="android:background">#66ffffff</item>
        <item name="android:paddingLeft">5dp</item>
        <item name="android:paddingBottom">10dp</item>
        <item name="android:textColor">#686868</item>
        <item name="android:textSize">15sp</item>
    </style>

</resources>

除“textSize”外,所有内容都应用于 TextView。配置的 textSize 高度中不会出现任何文本。任何想法,为什么这不起作用?

没有编译错误。

当我直接使用 TextView 应用属性“textSize”时,一切正常。

谢谢

【问题讨论】:

    标签: android android-layout text-size


    【解决方案1】:

    我对错误的“styles.xml”文件进行了更正。我有一个大于 16 的 API 样式文件。这个文件被使用了。但我编辑了标准的“styles.xml”。

    【讨论】:

      【解决方案2】:

      尝试在下面的文件夹结构中添加:

      res/values/dimens.xml
      
      res/values-small/dimens.xml
      
      res/values-normal/dimens.xml
      
      res/values-xlarge/dimens.xml
      

      例子:

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
         <dimen name="text_size">18sp</dimen>
      </resources>
      

      【讨论】:

        猜你喜欢
        • 2015-01-23
        • 2018-04-20
        • 2019-11-28
        • 1970-01-01
        • 2011-01-11
        • 1970-01-01
        • 1970-01-01
        • 2011-12-12
        • 1970-01-01
        相关资源
        最近更新 更多