标签:widget elevation yellow ane odi out idg compile match
今天学习了design包下的两个控件,记录一下,首先需要我们依赖
1 compile ‘com.android.support:design:25.0.0‘
之后在XML文件中就可以使用了
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 tools:context="com.wuxianedu.alianxi.MainActivity" 7 xmlns:app="http://schemas.android.com/apk/res-auto"> 8 9 <android.support.design.widget.FloatingActionButton 10 android:id="@+id/button" android:layout_centerInParent="true" 11 android:layout_width="wrap_content" app:rippleColor="#FF4F4F" 12 android:layout_height="wrap_content" app:fabSize="mini" 13 app:elevation="40dp" app:pressedTranslationZ="50dp" 14 android:src="@mipmap/ic_launcher"/> 15 </RelativeLayout>
属性说明
在XML文件中设置好了的效果图为
下面在JAVA文件中写另一个组件
1 package com.wuxianedu.alianxi; 2 3 import android.graphics.Color; 4 import android.support.design.widget.FloatingActionButton; 5 import android.support.design.widget.Snackbar; 6 import android.support.v7.app.AppCompatActivity; 7 import android.os.Bundle; 8 import android.view.View; 9 import android.widget.TextView; 10 import android.widget.Toast; 11 12 public class MainActivity extends AppCompatActivity { 13 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.activity_main); 18 //给在XML中写的组件设置点击事件 19 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 20 @Override 21 public void onClick(View view) { 22 //使用Snackbar弹出信息, 23 Snackbar snackbar = Snackbar.make(view,"我是提示信息",Snackbar.LENGTH_LONG); 24 //设置确定按钮 25 snackbar.setAction("确定", new View.OnClickListener() { 26 @Override 27 public void onClick(View view) { 28 Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show(); 29 } 30 }); 31 //修改弹出信息的颜色 32 snackbar.setActionTextColor(Color.GREEN); 33 //获取到弹出的View菜单 34 View views = snackbar.getView(); 35 //设置背景yans 36 views.setBackgroundColor(Color.BLUE); 37 TextView textView = (TextView) views.findViewById(R.id.snackbar_text); 38 textView.setTextColor(Color.YELLOW); 39 snackbar.show(); 40 } 41 }); 42 } 43 }
标签:widget elevation yellow ane odi out idg compile match
原文地址:http://www.cnblogs.com/langfei8818/p/6079158.html