TextView
<TextView
android:id="@+id/tv_one" # findViewById(R.id.tv_one);
android:layout_width="200dp" # 宽度,单位dp
android:layout_height="200dp" # 高度
android:text="@string/one_text" # 文本内容
android:textColor="#FFFF0000" # 透明度+RGB
android:textStyle="italic" # normal, bold, italic
android:textSize="30sp" # 字体大小,单位sp
android:background="#FFFFFF00" # 颜色、图片
android:gravity="center" # 文字、图片的位置
android:shadowColor="@color/black" # 阴影颜色
android:shadowRadius="3.0" # 阴影模糊度
android:shadowDx="10.0" # 阴影x轴偏移量
android:shadowDy="10.0" # 阴影y轴偏移量
android:singleLine="true" # 单行显示
android:ellipsize="marquee" # 跑马灯显示
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true" # 获取焦点
android:focusableInTouchMode="true" # 触摸
android:clickable="true" # 允许点击
/>
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;
}
}
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent">
<requestFocus/>
</TextView>
Button
@RemoteView
public class Button extends TextView
#设置成Bridge
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
#设置选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_baseline_account_balance_24" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_baseline_accessibility_new_24"/>
</selector>
#设置背景、背景色、前景色
<Button
android:id="@+id/button_tx"
android:text="@string/app_name"
android:background="@drawable/button_select"
android:backgroundTint="#ffff0000"
android:foreground="@color/black"
android:layout_width="200dp"
android:layout_height="100dp"/>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取Button对象
Button btn = findViewById(R.id.button_tx);
// 设置点击事件
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
// 设置长按事件
btn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});
// 设置触摸事件
btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
}
}
EditText
ImageView
ProgressBar
Notification
Toolbar
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar">
AlertDialog
PopupWindow