Android Material風格的應用(四)--FloatActionButton


添加 FloatActionButton和SnackBar

Android Material風格的應用(一)--AppBar TabLayout
Android Material風格的應用(二)--RecyclerView
Android Material風格的應用(三)--DrawerLayout
Android Material風格的應用(四)--FloatActionButton
Android Material風格的應用(五)--CollapsingToolbar


fab


工程源碼
activity_main.xml中的CoordinatorLayout中添加FloatActionButton

  <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fab" android:layout_gravity="right|bottom" android:layout_marginBottom="@dimen/md_keylines" android:layout_marginRight="@dimen/md_keylines" android:src="@drawable/ic_add"/>

MainActivity.java中添加邏輯處理,fab點擊時顯示Snackbar

  FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v,"This is Snackbar!!",Snackbar.LENGTH_LONG).show(); } });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM