Noteworthy property settings of TextView

Layout file settings

加粗
android:textStyle="bold" 
设置斜体
android:textStyle="italic"    //组合通过 | 符号链接
设置文字阴影
android:shadowColor="@color/black"  阴影颜色
android:shadowDx="0"  阴影X坐标
android:shadowDy="5"  阴影X坐标
android:shadowRadius="5"  

java code settings

添加删除线
txt1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

在代码中设置加粗
 txt2.getPaint().setFlags(Paint.FAKE_BOLD_TEXT_FLAG);
 
添加下划线
txt3.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

抗锯齿
textview.getPaint().setAntiAlias(true);

Automatically scale font size display

There are several properties in AppCompatTextView that can automatically scale fonts to fully display all fonts within the width of the control. The
key point is

  1. Version compatibility issues, you need to use the app tag
  2. When the font is reduced to the set minimum font size and still cannot be displayed, the display will still be omitted...
  3. Regarding whether the width and height of the control need to be fixed, that is, when set to wrap_content, it should be displayed in the maximum font size.
  4. If it is a custom textview, you need to inherit AppCompatTextView instead of TextView, otherwise there will be Android version compatibility issues
  5. You only need to add the following four lines of code to the textview control in xml to achieve the effect of automatically scaling the font size
app:autoSizeMaxTextSize="15sp"
app:autoSizeMinTextSize="12sp"
app:autoSizeTextType="uniform"
app:autoSizeStepGranularity="1sp" //每次字号变化的大小

Guess you like

Origin blog.csdn.net/qq_39734865/article/details/88973278