标签:
效果图:
<!-- app:backgroundTint="@color/colorPrimary"设置FAB的背景颜色,也可以通过<color name="colorAccent">#08f704</color>来设置 app:fabSize="mini"设置FAB的大小,取值两种,mini-48dp,normal-56dp app:elevation="5dp"设置FAB的Z轴高度 app:borderWidth="5dp"设置圆环的宽度 --> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="fabClick" app:borderWidth="5dp" app:elevation="5dp" app:fabSize="normal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="dismissSnackBar"/>
public class MainActivity extends AppCompatActivity { private Snackbar snackbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void fabClick(View view) { // Toast.makeText(MainActivity.this, "123", Toast.LENGTH_SHORT).show(); //Snackbar.LENGTH_INDEFINITE一直显示 snackbar = Snackbar.make(view, "HelloWorld", Snackbar.LENGTH_INDEFINITE).setAction("go", new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "456", Toast.LENGTH_SHORT).show(); } }).setActionTextColor(Color.RED); //获取到显示HelloWorld的控件 View view1 = snackbar.getView(); view1.setBackgroundColor(Color.WHITE); TextView textView = (TextView) view1.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.BLUE); snackbar.show(); } public void dismissSnackBar(View view) { snackbar.dismiss(); } }
标签:
原文地址:http://www.cnblogs.com/anni-qianqian/p/5457909.html