安卓系统中如何设置TextView的字体默认大小

  介绍

本篇文章为大家展示了Android中如何设置TextView的字体默认大小,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

对于设置TextView的字体默认大小对于UI界面的好看程度是很重要的,小屏幕设置的文字过大或者大屏幕设置的文字过小都造成UI的不美观

现在就让我们学习自适应大小的TextView控件,

实现依靠于第三方类库

第三方类

和正常的使用TextView一样,只需要将要自适应的TextView标签设置为& lt; me.grantland.widget.AutofitTextView/祝辞

注意:一定要设置为单行,否定无法显示效果

<代码> Android:单行模式=皌rue"

& lt; me.grantland.widget.AutofitTextView   android: id=癅 + id/output_autofit"   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:文本=癅string/example"   android: textSize=?0 sp"   android:重力=癱enter"   android:单行模式=皌rue"   最适合的:minTextSize=? sp"/在

<强>布局文件:

& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比;   http://schemas.android.com/apk/res/android" & lt; ScrollView xmlns: android=?;xmlns:最适合的=癶ttp://schemas.android.com/apk/res-auto"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"比;   LinearLayout & lt;   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:取向=皏ertical"   比;   EditText & lt;   android: id=癅 + id/input"   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:单行模式=皌rue"   android:提示=癅string/input_hint"   android:文本=癅string/example"/比;   & lt; TextView   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:文本=癅string/label_normal"/比;   & lt; TextView   android: id=癅 + id/output"   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:文本=癅string/example"   android: textSize=?0 sp"   android:重力=癱enter"/比;   & lt; TextView   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:文本=癅string/label_autofit"/比;   & lt; me.grantland.widget.AutofitTextView   android: id=癅 + id/output_autofit"   android: layout_width=癿atch_parent"   android: layout_height=皐rap_content"   android:文本=癅string/example"   android: textSize=?0 sp"   android:重力=癱enter"   android:单行模式=皌rue"   最适合的:minTextSize=? sp"/比;   & lt;/LinearLayout>   & lt;/ScrollView>      activity_main。xml

& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比;   & lt; resources>   & lt;字符串名称=癮pp_name"祝辞Texttest   & lt;字符串名称=癮ction_settings"祝辞Settings   & lt;字符串名称=癶ello_world"祝辞Hello world ! & lt;/string>   & lt;字符串名称=癷nput_hint"祝辞text   & lt;字符串名称=發abel_normal"祝辞正常:& lt;/string>   & lt;字符串名称=發abel_autofit"在最适合的:& lt;/string>   & lt;字符串名称=癳xample"祝辞;这是一个example   & lt;/resources>

包com.example.texttest;
  进口android.app.Activity;
  进口android.os.Bundle;
  进口android.text.Editable;
  进口android.text.TextWatcher;
  进口android.view.Menu;
  进口android.widget.EditText;
  进口android.widget.TextView;
  公开课MainActivity延伸活动{
  私人TextView mOutput;
  私人TextView mAutofitOutput;
  @Override
  保护空白>上述内容就是Android中如何设置TextView的字体默认大小,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

安卓系统中如何设置TextView的字体默认大小