MaterialDesign(一)

MaterialDesign(一)

修改应用内部的一些样式和颜色

1

  • 修改状态栏颜色:
//xml中修改
//AndroidManifest -> android:theme="@style/AppTheme" -> 
<item name="colorPrimaryDark">@color/colorPrimaryDark</item><!--状态栏颜色-->

/**
* java代码中修改
* 注意:这里需要API21及以上的才可以修改
*/
Window window = getWindow();
window.setStatusBarColor(0xffffff);
  • 修改导航栏颜色
//xml中修改
//AndroidManifest -> android:theme="@style/AppTheme"
<item name="android:navigationBarColor">@color/colorAccent</item>

//
/**
* java代码中修改
* 注意:这里需要API21及以上的才可以修改
*/
Window window = getWindow();
window.setNavigationBarColor(0x000000);

MaterialDesigner新增了Z轴

2

  • 在xml中修改自定义的drawable颜色
android:tint="@android:color/holo_green_dark"
  • 效果图

Z轴

  • xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/circle1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circle"
        android:layout_margin="50dp"/>
    <ImageView
        android:id="@+id/circle2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/circle"
        android:tint="@android:color/holo_green_dark"<!--修改drawable的颜色-->
        android:layout_margin="65dp"/>
</RelativeLayout>
  • java代码
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {

    private ImageView mCircle1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mCircle1 = (ImageView) findViewById(R.id.circle1);
        mCircle1.setOnTouchListener(this);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
      //数值越大,控件的Z轴就越高  
      switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                if (Build.VERSION.SDK_INT >= 21)
                    mCircle1.setTranslationZ(1);
                break;
            case MotionEvent.ACTION_DOWN:
                if (Build.VERSION.SDK_INT >= 21)
                    mCircle1.setTranslationZ(0);
                break;
        }
        return true;
    }
}

水波纹效果

水波纹

  • 在res下新建 layout-v21包
  • 把实现了水波纹效果控件的布局复制到layout-v21
  • 在要实现水波纹的控件上添加以下代码
//无边界
android:background="?android:selectableItemBackgroundBorderless"
//有边界
android:background="?android:selectableItemBackground"

在android中 ? 和 @ 的区别

  • @ 代表引用资源,直接就是获取到值
  • ? 代表引用主题属性,属性的值是在另外的地方设置的

  • @

@的含义2

@的含义1

  • ?

问号的含义1

问号的含义2

CardView

  • 先找到CardView的aar包

card_aar

cardView1

  • cardElevation :阴影效果
  • cardCornerRadius : 圆角效果
  • cardBackgroundColor :背景颜色
 <android.support.v7.widget.CardView
        android:layout_width="300dp"
        android:layout_height="50dp"
        app:cardElevation="10dp"
        app:cardCornerRadius="20dp"
        app:cardBackgroundColor="#ff0"
        android:layout_gravity="center"
        android:layout_marginTop="50dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="22sp"
            android:text="CardView"/>
    </android.support.v7.widget.CardView>

TextInputLayout

  • 准备工作 : 导入design包

  • app:hintAnimationEnabled : 是否开启提示的动画效果,默认开启

  • app:counterEnabled : 对输入的字进行计数
  • app:counterMaxLength : 设置总的字个数
  • android:hint : 设置提示的内容
  • android:textColorHint : 设置输入框里面字体的颜色
  • setError : 设置错误提示,在java代码中设置

textInputLayout

//设置错误信息
mPwdEt.setError("不能为空!!!");
  • xml代码
<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:textColorHint="#0ff"><!--修改内部提示语的颜色-->

        <EditText
            android:id="@+id/user_et"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="账号: "/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        app:hintTextAppearance="@style/MyStyle">

        <EditText
            android:id="@+id/pwd_et"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="密码: "/>
    </android.support.design.widget.TextInputLayout>
  • style代码
    <style name="MyStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">#AA00FF</item><!--外部提示字体的颜色-->
        <item name="android:textSize">22sp</item><!--外部提示字体的大小-->
    </style>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">#0000FF</item><!--这里可以修改边框和边框外边提示字体的颜色-->
    </style>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Laihh933260

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值