차근차근/안드로이드 스튜디오

플로팅 액션 버튼 만들기

예쁜꽃이피었으면 2016. 8. 10. 10:30


https://www.youtube.com/watch?v=mTv3JxdVb9o


http://stackoverflow.com/questions/30699302/android-design-support-library-fab-menu



50down voteaccepted

Currently, there is no widget provided in the Design Library. The only way to do it quickly and easily is by using third-party libraries.

You can obviously do this using the Design Library too, but it will be a huge work and require a lot of time. I have mentioned some useful libraries, that can help you achieve this.

1) Rapid Floating Button (link)

2) Floating Action Button (link)

3) Floating Action Button (link)

4) Android Floating Action Button (link) - This is the one I am using.    -> 난 이거 따라해봄

Thanks.



-> 4번   https://github.com/futuresimple/android-floating-action-button




Android Floating Action Menu with Social Icons – AndroidMkab

http://androidmkab.com/2016/06/07/android-floating-action-menu-with-social-icons-androidmkab/

https://youtu.be/iqtfbEU0SUY



되긴하는데 위치나.. 아이콘 크기 등을 변경해야 하고


그.. xml을 다시 봐야 할듯..





검색어 : layout_marginbottom not working


http://stackoverflow.com/questions/8642071/why-marginbottom-not-working




down voteaccepted

marginBottom has no effect if you set android:layout_height="wrap_content" for <RelativeLayout>, instead set it as match_parent and check.


음.. 

<com.github.clans.fab.FloatingActionMenu
android:id="@+id/social_floating_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_height="match_parent"


이렇게 바꿈


SNSlogo.zip


테스트 했던 이미지 ( http://www.flaticon.com/packs/logotypes )


Design_플로팅 액션 버튼.vol1.egg

Design_플로팅 액션 버튼.vol2.egg

Design_플로팅 액션 버튼.vol3.egg

Design_플로팅 액션 버튼.vol4.egg

Design_플로팅 액션 버튼.vol5.egg

Design_플로팅 액션 버튼.vol6.egg

Design_플로팅 액션 버튼.vol7.egg


fab-1.6.3-javadoc.jar

fab-1.6.3-sources.jar



[ build.gradle ]


apply plugin: 'com.android.application'


android {

    compileSdkVersion 23

    buildToolsVersion "23.0.0"


    defaultConfig {

        applicationId "design.test.uk.design"

        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'])

    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.1.1'

    compile 'com.android.support:design:23.1.0'

    compile 'com.github.clans:fab:1.6.2'

}


[ MainActivity.java ]

package design.test.uk.design;


import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;


import com.github.clans.fab.FloatingActionButton;

import com.github.clans.fab.FloatingActionMenu;


public class MainActivity extends Activity implements View.OnClickListener {


    FloatingActionMenu materialDesignFAM;

    FloatingActionButton floatingActionButton1,floatingActionButton2,floatingActionButton3,floatingActionButton4,

            floatingActionButton5,floatingActionButton6;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        materialDesignFAM = (FloatingActionMenu) findViewById(R.id.social_floating_menu);


        floatingActionButton1 = (FloatingActionButton) findViewById(R.id.floating_facebook);

        floatingActionButton2 = (FloatingActionButton) findViewById(R.id.floating_twitter);

        floatingActionButton3 = (FloatingActionButton) findViewById(R.id.floating_linkdin);

        floatingActionButton4 = (FloatingActionButton) findViewById(R.id.floating_google_plus);

        floatingActionButton5 = (FloatingActionButton) findViewById(R.id.floating_instagram);

        floatingActionButton6 = (FloatingActionButton) findViewById(R.id.floating_youtube);


        floatingActionButton1.setOnClickListener(this);

        floatingActionButton2.setOnClickListener(this);

        floatingActionButton3.setOnClickListener(this);

        floatingActionButton4.setOnClickListener(this);

        floatingActionButton5.setOnClickListener(this);

        floatingActionButton6.setOnClickListener(this);


    }



    public static Intent getOpenFacebookIntent(Context context){

        try{

            context.getPackageManager().getPackageInfo("com.facebook.kaana",0);


            return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/376227335860239"));

        }catch(Exception e){

            return new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.facebook.com/karthikofficialpage"));

        }

    }



    public static Intent getOpenTwitterIntent(Context context) {


        try {

            context.getPackageManager().getPackageInfo("com.twitter.android", 0);

            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/drkarthiik"));

        } catch (Exception e) {

            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/drkarthiik"));

        }

    }


    public static Intent getOpenLinkdinIntent(Context context) {


        try {

            context.getPackageManager() .getPackageInfo("com.linkedin.android", 0);

            return new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.linkedin.com/in/karthikm128"));

        } catch (Exception e) {

            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.linkedin.com/in/karthikm128"));

        }

    }


    public static Intent getOpenGPlusIntent(Context context) {


        try {

            context.getPackageManager().getPackageInfo("com.google.android.apps.plus", 0);

            return new Intent(Intent.ACTION_VIEW,Uri.parse("https://plus.google.com/u/0/+KarthikM128"));

        } catch (Exception e) {

            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/u/0/+KarthikM128"));

        }

    }


    public static Intent getOpenInstagramIntent(Context context) {


        try {

            context.getPackageManager().getPackageInfo("com.instagram.android", 0);

            return new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.instagram.com/accounts/login/"));

        } catch (Exception e) {

            return new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.instagram.com/accounts/login/"));

        }

    }


    public static Intent getOpenYouTubeIntent(Context context) {


        try {

            context.getPackageManager().getPackageInfo("com.google.android.youtube", 0);

            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/karthikm128"));

        } catch (Exception e) {

            return new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.youtube.com/karthikm128"));

        }

    }



    @Override

    public void onClick(View v) {


        switch(v.getId()){

            case R.id.floating_facebook:

                Intent facebookIntent = getOpenFacebookIntent(MainActivity.this);

                startActivity(facebookIntent);

                break;


            case R.id.floating_twitter:

                Intent twitterIntent = getOpenTwitterIntent(MainActivity.this);

                startActivity(twitterIntent);

                break;


            case R.id.floating_linkdin:

                Intent linkdinIntent = getOpenLinkdinIntent(MainActivity.this);

                startActivity(linkdinIntent);

                break;


            case R.id.floating_google_plus:

                Intent googleplusIntent = getOpenGPlusIntent(MainActivity.this);

                startActivity(googleplusIntent);

                break;


            case R.id.floating_instagram:

                Intent instagramIntent = getOpenInstagramIntent(MainActivity.this);

                startActivity(instagramIntent);

                break;


            case R.id.floating_youtube:

                Intent youtubeIntent = getOpenYouTubeIntent(MainActivity.this);

                startActivity(youtubeIntent);

                break;


        }


    }

}


[ IntroActivity.java ] // 플로팅액션바는 아닌데 intro페이지 코딩도 되어있어서 추가

package design.test.uk.design;


import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;


public class IntroActivity extends Activity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_intro);


        Handler handler = new Handler();

        handler.postDelayed(new Runnable(){

            public void run(){

                Intent intent = new Intent(IntroActivity.this,MainActivity.class);

                startActivity(intent);

            //    startActivity(new Intent(this.getApplicationContext(),MainActivity.class));

                finish();

            }

        },2000);

    }

}


// 참고 : https://www.android-tech.io/2016/01/03/%EB%91%98%EC%A7%B8%EB%A7%88%EB%8B%B9-01%EC%9E%A5-02%EC%A0%88-%EC%8B%9C%EC%9E%91-%ED%99%94%EB%A9%B4%EC%9D%B8-%EC%9D%B8%ED%8A%B8%EB%A1%9C-%ED%99%94%EB%A9%B4-%EC%B6%94%EA%B0%80%ED%95%98%EA%B8%B0/



[ activity_main.xml ]


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_height="match_parent"

    android:layout_width="match_parent"

    xmlns:fab="http://schemas.android.com/apk/res-auto"

    android:orientation="vertical"

    xmlns:android="http://schemas.android.com/apk/res/android">


    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="main화면"/>




    <com.github.clans.fab.FloatingActionMenu

        android:id="@+id/social_floating_menu"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_alignParentBottom="true"

        android:layout_alignParentRight="true"

        android:layout_marginTop="5dp"

        android:layout_marginBottom="5dp"

        android:layout_marginLeft="5dp"

        android:layout_marginRight="5dp"

        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 Social Icons"

        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/floating_facebook"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_fb"

            fab:fab_size="mini" />


        <com.github.clans.fab.FloatingActionButton

            android:id="@+id/floating_twitter"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_tw"

            fab:fab_size="mini" />


        <com.github.clans.fab.FloatingActionButton

            android:id="@+id/floating_linkdin"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_in"

            fab:fab_size="mini" />


        <com.github.clans.fab.FloatingActionButton

            android:id="@+id/floating_google_plus"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_g_plus"

            fab:fab_size="mini" />


        <com.github.clans.fab.FloatingActionButton

            android:id="@+id/floating_instagram"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_insta"

            fab:fab_size="mini" />


        <com.github.clans.fab.FloatingActionButton

            android:id="@+id/floating_youtube"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:src="@mipmap/action_yt"

            fab:fab_size="mini" />


    </com.github.clans.fab.FloatingActionMenu>


</LinearLayout>


[ activity_intro.xml ]


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

    android:layout_height="match_parent"

    android:layout_width="match_parent"

    android:orientation="vertical"

    xmlns:android="http://schemas.android.com/apk/res/android">



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge"

        android:text="Intro화면"

        android:id="@+id/textView"

        android:layout_gravity="center_horizontal" />

</LinearLayout>


[ colors.xml ]


<?xml version="1.0" encoding="utf-8"?>

<resources>

    <color name="colorPrimary">#3F51B5</color>

    <color name="colorPrimaryDark">#303F9F</color>

    <color name="colorAccent">#FF4081</color>

</resources>




[ dimens.xml ]


<resources>

    <!-- Default screen margins, per the Android Design guidelines. -->

    <dimen name="activity_horizontal_margin">16dp</dimen>

    <dimen name="activity_vertical_margin">16dp</dimen>

</resources>




[ strings.xml ]


<resources>

    <string name="app_name">Design</string>

</resources>





[ styles.xml ]


<resources>


    <!-- Base application theme. -->

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <item name="colorAccent">@color/colorAccent</item>

    </style>


</resources>




반응형

'차근차근 > 안드로이드 스튜디오' 카테고리의 다른 글

앱이 최초실행인지 알아야 한다  (0) 2016.08.24
네비게이션 드로어 만들기  (0) 2016.08.10
intro 화면만들기  (0) 2016.08.10
gson을 써보려는데...  (0) 2016.07.26
안드로이드 참고 링크  (0) 2016.07.26