Adroid MD: TextInputLayout/FloatingActionButton/SnackBar

1.TextInputLayout

是一个布局,其中需要包裹一个EditText

<android.support.design.widget.TextInputLayout
        android:id="@+id/text_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:errorEnabled="true">
        <EditText 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>

代码

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_textinputlayout);
		
		layout = (TextInputLayout) findViewById(R.id.text_input_layout);
		EditText editText = layout.getEditText();
		layout.setHint("请输入姓名");
		editText.addTextChangedListener(this);
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if(s.length() > 4){
			layout.setErrorEnabled(true);
			layout.setError("名字输入的太长了...");
		}else{
			layout.setErrorEnabled(false);
		}
	}

	@Override
	public void afterTextChanged(Editable s) {
	}


2.FloatingActionButton

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.example.androiddesigndemo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaffffcc"
    android:orientation="vertical" >

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/meinv" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/meinv"
        app:backgroundTint="#ff0000"
        app:backgroundTintMode="multiply"
        app:borderWidth="5dp"
        app:elevation="1dp"
        app:fabSize="normal"
        app:rippleColor="#0000ff" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/meinv"
        app:backgroundTint="#ff0000"
        app:backgroundTintMode="multiply"
        app:borderWidth="5dp"
        app:fabSize="normal"
        app:pressedTranslationZ="0dp"
        app:rippleColor="#0000ff" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/meinv"
        app:backgroundTint="#ff0000"
        app:backgroundTintMode="multiply"
        app:borderWidth="5dp"
        app:elevation="1dp"
        app:fabSize="normal"
        app:pressedTranslationZ="0dp"
        app:rippleColor="#0000ff"/>
    <!-- app:pressedTranslationZ="20dp" 点击的时候阴影的深度 -->
    <!-- app:elevation="20dp" 图像背部阴影z轴深度(没有点击)-->
    <!-- app:backgroundTint="#ff0000" 圆形背景颜色 -->
    <!-- app:backgroundTintMode="screen" 着色方式 -->
    <!-- app:rippleColor="#0000ff" 点击时背景颜色 -->
    <!-- app:fabSize="mini" 控件大小显示(也就是推荐的空间大小,可能是希望我们不要设置width和height为精确的值) -->

	<!-- app:layout_anchor="@id/appbar" 设置互动按钮的锚点-->
	<!-- app:layout_anchorGravity="bottom|right|end"  设置按钮在描点的位置-->

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#ff0000"
        app:backgroundTintMode="screen"
        app:borderWidth="5dp"
        app:elevation="1dp"
        app:fabSize="normal"
        app:pressedTranslationZ="0dp"
        app:rippleColor="#0000ff" />

</LinearLayout>


3.SnackBar

// Snackbar 中 message 和 anction 布局文件时是在 布局文件 layout_snackbar_include.xml 中 ,其显示样式是可以在其中修改,要是能够下载到源码就更好了
  String str = "给你要一个妞!!!";
  final Snackbar snackBar = Snackbar.make(btn, str, Snackbar.LENGTH_LONG);//findViewById(R.id.ll)
  View view = snackBar.getView();
  view.setBackgroundColor(Color.CYAN); // 设置snackbar
  snackBar.show();
  snackBar.setActionTextColor(Color.WHITE);
  snackBar.setAction("好的", new OnClickListener() {
   
   @Override
   public void onClick(View v) {
    snackBar.dismiss();
   }
  });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值