本文主要是介绍Android Floating Action Menu 简单应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文:https://www.viralandroid.com/2016/02/android-floating-action-menu-example.html
build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.1.2'
compile 'com.android.support:design:27.1.1'compile 'com.github.clans:fab:1.6.4'
}
XML Layout File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"><com.github.clans.fab.FloatingActionMenu
android:id="@+id/material_design_android_floating_action_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#da3c2f"
fab:menu_colorPressed="#dc4b3f"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_label="Floating Action Menu"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/fab_add"
fab:menu_labels_colorNormal="#333"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66aff198"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="4dp"
fab:menu_showShadow="true"><com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_send"
fab:fab_label="Menu Item 1"
fab:fab_size="mini" /><com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_photo"
fab:fab_label="Menu Item 2"
fab:fab_size="mini" /><com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_edit"
fab:fab_label="Menu Item 3"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
Java Activity File
package viralandroid.com.androidmaterialdesigntutorial;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;public class MaterialDesignFloatingActionMenu extends AppCompatActivity {
FloatingActionMenu materialDesignFAM;
FloatingActionButton floatingActionButton1, floatingActionButton2, floatingActionButton3;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.material_design_floating_action_menu);materialDesignFAM = findViewById(R.id.material_design_android_floating_action_menu);
floatingActionButton1 = findViewById(R.id.material_design_floating_action_menu_item1);
floatingActionButton2 = findViewById(R.id.material_design_floating_action_menu_item2);
floatingActionButton3 = findViewById(R.id.material_design_floating_action_menu_item3);floatingActionButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO}
});
floatingActionButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO}
});
floatingActionButton3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO}
});
}
}
运行错误:
com.github.clans.fab.FloatingActionButton cannot be cast to android.support.design.widget.FloatingAction
导入包应该是:
import com.github.clans.fab.FloatingActionMenu;
import com.github.clans.fab.FloatingActionButton;
不应该有:
import android.support.design.widget.FloatingAction
这篇关于Android Floating Action Menu 简单应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!