[英]Text size does not change in TextView using a style in Android Studio
I am trying to style some TextViews to have a given text size. 我试图将一些TextViews设置为具有给定的文本大小。 Changing the size in the style does nothing to the TextView, while changing it in the layout XML has the correct effect. 更改样式中的大小对TextView没有任何作用,而在布局XML中更改它具有正确的效果。 What am I missing? 我错过了什么?
Style: 样式:
<style name="SliderTextTheme">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">25sp</item>
<item name="android:textAlignment">center</item>
</style>
Layout XML for the TextView: TextView的布局XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:id="@+id/image_frame"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="5">
<ImageView
android:id="@+id/color_wheel"
android:src="@drawable/color_wheel_730"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
<LinearLayout
android:id="@+id/slider_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_red"
android:text="@string/color_red"/>
<SeekBar
style="@style/ColorSeekBar"
android:id="@+id/red_seekbar"
android:progressTint="@color/RGBW_red"
android:thumbTint="@color/RGBW_red" />
<TextView
android:id="@+id/red_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_red"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_green"
android:text="@string/color_green"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_green"
android:thumbTint="@color/RGBW_green" />
<TextView
android:id="@+id/green_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_green"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_blue"
android:text="@string/color_blue"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_blue"
android:thumbTint="@color/RGBW_blue" />
<TextView
android:id="@+id/blue_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_blue"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_white"
android:text="@string/color_white"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_white"
android:thumbTint="@color/RGBW_white" />
<TextView
android:id="@+id/white_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_white"
tools:text="100" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/button_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom">
<Button
android:id="@+id/test_button_1"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="Send Colors"/>
</RelativeLayout>
</LinearLayout>
Thank you in advance. 先感谢您。 Tom 汤姆
I was able to get your style to work and adjust the text size by by changing 我能够让你的风格发挥作用,并通过改变来调整文本大小
<item name="android:layout_width">0dp</item>
to 至
<item name="android:layout_width">wrap_content</item>
If you require the 0dp width to work with your weight attribute, check to make sure that the TextView you are manipulating is definitely inside of a LinearLayout. 如果您需要使用0dp宽度来处理权重属性,请检查以确保您正在操作的TextView绝对位于LinearLayout内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.