----------------------------gradle(build.gradle)------------------------------
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.galaxystech.fabdemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
}
-----------------activity_main.xml------------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
--------------------------------MainActivity.java----------------------
package com.galaxystech.fabdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create an icon
ImageView icon = new ImageView(this);
icon.setImageResource(R.mipmap.ic_launcher);
FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
.setContentView(icon)
.build();
SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
// repeat many times:
ImageView itemIcon1 = new ImageView(this);
itemIcon1.setImageResource(R.mipmap.ic_launcher);
ImageView itemIcon2 = new ImageView(this);
itemIcon2.setImageResource(R.mipmap.ic_launcher);
ImageView itemIcon3 = new ImageView(this);
itemIcon3.setImageResource(R.mipmap.ic_launcher);
SubActionButton button1 = itemBuilder.setContentView(itemIcon1).build();
SubActionButton button2 = itemBuilder.setContentView(itemIcon2).build();
SubActionButton button3 = itemBuilder.setContentView(itemIcon3).build();
//attach the sub buttons to the main button
FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this)
.addSubActionView(button1)
.addSubActionView(button2)
.addSubActionView(button3)
.attachTo(actionButton)
.build();
}
}
No comments:
Post a Comment