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模式

<DatePicker
    android:calendarViewShown="false"
    android:datePickerMode="spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

后续持续更新...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,804评论 25 709
  • 那一天,我终于打开心灵的锁,走了出来,不再将自己锁在幽暗的世界。却突然发现,原来一切都是自己错误的把这个感知,当成...
    华枝春满5339阅读 511评论 1 4
  • 不习惯 不喜欢
    高处不胜寒1阅读 287评论 0 0