Android常用资源总结

前言

在我们的日常开发当中,经常会使用到Android系统自带的资源,比如图片,主题,样式等等,所以我将一些常用的东西给总结了一下

1. 调用系统资源带有@和?,两者的区别如下:

  1. 调用系统的样式,主题,动画资源等一般以@开头

    android:theme="@android:style/Theme.Dialog"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    
  2. 调用attr下的资源设置view的属性,一般以?开头

     android:textColor="?android:attr/textColorPrimary"
     style="?android:attr/progressBarStyleLarge"
    

2. Toolbar高度

?attr/actionBarSize

3. Toast背景和字体设置

Toast toast = Toast.makeText(this, "", Toast.LENGTH_SHORT);//创建Toast对象
toast.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));//设置Toast背景
TextView tvMessage = toast.getView().findViewById(android.R.id.message);
tvMessage.setTextColor(getResources().getColor(R.color.colorPrimary));//设置Toast字体颜色

4. Snackbar背景和字体设置

Snackbar snackbar = Snackbar.make(view, "", Snackbar.LENGTH_SHORT);
snackbar.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));//设置Snackbar背景
TextView tvSnackBarText = snackbar.getView().findViewById(R.id.snackbar_text);
tvSnackBarText.setTextColor(getResources().getColor(R.color.colorPrimary));//设置Snackbar字体颜色

5. 系统自带视图动画

android.R.anim.fade_in,android.R.anim.fade_out//举个例子 有很多

6. 调用系统drawable

@android:drawable/btn_dialog

7. Button设置文字为英文时全部为大写,解决方法

方式一

android:textAllCaps="false"

方式二

android:textAppearance="?android:attr/textAppearance"

8. TabLayout英文状态下字母全部为大写的解决方法

app:tabTextAppearance="?android:attr/textAppearanceSmall"

9. 设置DatePicker为Spinner模式


后续持续更新...

你可能感兴趣的:(Android常用资源总结)