每日记录(AndroidStudio入门基础(四)——基础组件)

TextView
①文字的大小、颜色

下面代码中我的备注方式是不对的哈

<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TREE"
android:textColor="#6BD089" !!设置文字的颜色
android:textSize="50sp" !!设置文字的大小,注意单位sp
/>


②文字显示不完时用...代替

<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="We wish each other a long life so as to share the beauty of this graceful moonlight, even though miles apart."
android:textColor="#6BD089"
android:textSize="50sp"
android:maxLines="1" !!!
android:ellipsize="end" !!!
/>


③文字上显示中划线、下划线

显示中划线和下划线这个样式就是.xml文件里面设置不了的样式了,需要在java代码中设置。

<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world"
android:textColor="#6BD089"
android:textSize="50sp"
/>
<TextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world"
android:textColor="#6BD089"
android:textSize="50sp"
/>

public class SecondActivity extends AppCompatActivity {
TextView textView1,textView2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);

textView1=findViewById(R.id.tv_1);
textView2=findViewById(R.id.tv_2);

//中划线
textView1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//下划线
textView2.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
}
}

 

 

④跑马灯效果

<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="We wish each other a long life so as to share the beauty of this graceful moonlight, even though miles apart."
android:textColor="#6BD089"
android:textSize="50sp"
android:singleLine="true" !!
android:ellipsize="marquee" !!
android:marqueeRepeatLimit="marquee_forever" !!
android:focusable="true" !!
android:focusableInTouchMode="true" !!
/>

posted @   傲世小苦瓜  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示