android——悬浮图标(FloatingActionButton)

不念不忘少年蓝@ 2022-06-03 06:20 463阅读 0赞

效果图:

CenterCenter 1

添加依赖:

  1. compile 'com.getbase:floatingactionbutton:1.9.0'

布局文件:

  1. <com.getbase.floatingactionbutton.FloatingActionsMenu android:id="@+id/multiple_actions"
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:layout_alignParentBottom="true"
  5. android:layout_alignParentRight="true"
  6. android:layout_alignParentEnd="true"
  7. fab:fab_labelStyle="@style/menu_labels_style"
  8. android:layout_marginBottom="16dp"
  9. android:layout_marginRight="16dp"
  10. android:layout_marginEnd="16dp"
  11. skin:enable="true"
  12. >
  13. <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_grid"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. fab:fab_icon="@mipmap/floataction_grid"
  17. skin:enable="true"
  18. fab:fab_colorPressed="#f1f1f1"/>
  19. <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_list"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. fab:fab_icon="@mipmap/floataction_list"
  23. skin:enable="true"
  24. fab:fab_colorPressed="#f1f1f1"/>
  25. <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_staggle"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. fab:fab_icon="@mipmap/floataction_staggle"
  29. skin:enable="true"
  30. fab:fab_colorPressed="#f1f1f1"/>
  31. </com.getbase.floatingactionbutton.FloatingActionsMenu>

styles.xml

  1. <style name="menu_labels_style">
  2. <item name="android:background">@drawable/fab_label_background</item>
  3. <item name="android:textColor">@color/white</item>
  4. </style>

fab_label_background.xml

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  2. <solid android:color="@color/black_semi_transparent"/>
  3. <padding android:left="16dp"
  4. android:top="4dp"
  5. android:right="16dp"
  6. android:bottom="4dp"/>
  7. <corners android:radius="2dp"/>
  8. </shape>

Activity

  1. action_grid.setOnClickListener(new View.OnClickListener() {
  2. @Override public void onClick(View view) {
  3. GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
  4. xRecyclerView.setLayoutManager(manager);
  5. adapter = new WelfareRecycleViewAdapter(getContext(), list, 2);
  6. xRecyclerView.setAdapter(adapter);
  7. actionsMenu.collapse();
  8. }
  9. });
  10. action_list.setOnClickListener(new View.OnClickListener() {
  11. @Override public void onClick(View view) {
  12. LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
  13. layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  14. xRecyclerView.setLayoutManager(layoutManager);
  15. adapter = new WelfareRecycleViewAdapter(getContext(), list, 1);
  16. xRecyclerView.setAdapter(adapter);
  17. actionsMenu.collapse();
  18. }
  19. });
  20. action_staggle.setOnClickListener(new View.OnClickListener() {
  21. @Override public void onClick(View view) {
  22. StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2,
  23. StaggeredGridLayoutManager.VERTICAL);
  24. xRecyclerView.setLayoutManager(manager);
  25. adapter = new WelfareRecycleViewAdapter(getContext(), list, 3);
  26. xRecyclerView.setAdapter(adapter);
  27. actionsMenu.collapse();
  28. }
  29. });

发表评论

表情:
评论列表 (有 0 条评论,463人围观)

还没有评论,来说两句吧...

相关阅读