文章目录
- Text_View
- 基础属性
- 字体阴影
- 跑马灯
- **activity_main.xml**
- MyTextview
- button
Text_View
ctrl+右键可以看到属性
代码整理采用的快捷键是ctrl+alt+L(电脑qq锁定快捷键,退一下qq就行了)
基础属性
字体阴影
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_one"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#A36F5E8E"
android:gravity="center"
android:shadowColor="@color/black"
android:shadowRadius="6"
android:shadowDx="5"
android:shadowDy="5"
android:text="@string/ccs"
android:textColor="#6332BA"
android:textSize="30sp"
android:textStyle="bold">
</TextView>
</LinearLayout>
跑马灯
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.text1.MyTextview
android:id="@+id/tv_one"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#A36F5E8E"
android:gravity="center"
android:shadowColor="@color/black"
android:shadowRadius="6"
android:shadowDx="5"
android:shadowDy="5"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/ccs"
android:textColor="#6332BA"
android:textSize="30sp"
android:textStyle="bold">
</com.example.text1.MyTextview>
</LinearLayout>
MyTextview
方法一(麻烦):新建一个类
package com.example.text1;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
public class MyTextview extends TextView {
public MyTextview(Context context) {
super(context);
}
public MyTextview(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyTextview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;
}
}
方法二:直接加一句代码:
<requestFocus/>