33
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android StudioでMaterialDesignLibraryを使ってみた。

Last updated at Posted at 2015-01-09

MaterialDesignLibrary

ライブラリ導入手順

1.Android StudioのTerminalでプロジェクトルートに移動して以下のコマンドを実行します。実行すると.gitmodulesというファイルとMaterialDesignLibraryというフォルダがプロジェクトルートに追加されます。

$ git submodule add https://github.com/navasmdc/MaterialDesignLibrary.git
$ git submodule init
$ git submodule update

2.app/build.gradleのdependenciesに以下を追加。

compile project(':MaterialDesignLibrary:AndroidStudio:MaterialDesign:app')

3.setting.gradleに以下を追加。

include ':MaterialDesignLibrary:AndroidStudio:MaterialDesign:app'

4.親プロジェクトで使用しているGradleプラグインにバージョンを合わせます。
MaterialDesignLibrary/AndroidStudio/MaterialDesign/build.gradle

classpath 'com.android.tools.build:gradle:0.12.+'

↓ 変更

classpath 'com.android.tools.build:gradle:1.0.0'

5.ライブラリプロジェクトとして認識させます
MaterialDesignLibrary/AndroidStudio/MaterialDesign/app/build.gradle

apply plugin: 'com.android.application'

↓ 変更

apply plugin: 'com.android.library'

6.defaultConfigのminSdkVersionを変更し、applicationIdを削除します。
MaterialDesignLibrary/AndroidStudio/MaterialDesign/app/build.gradle

defaultConfig {
        applicationId 'com.gc.materialdesign'
        minSdkVersion 19

↓ 変更

defaultConfig {
        //applicationId 'com.gc.materialdesign'
        minSdkVersion 8

導入

Android4.4(KitKat)でウィジェットだけ配置してみました。

activity_my.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.gc.materialdesign.views.ButtonFlat
        android:id="@+id/buttonflat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#1E88E5"
        android:text="カラーセレクター" />

    <com.gc.materialdesign.views.ButtonRectangle
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#1E88E5"
        android:text="ダイアログ"
        android:layout_below="@+id/buttonflat"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <com.gc.materialdesign.views.ButtonFloat
        android:id="@+id/buttonFloat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="26dp"
        android:background="#1E88E5"
        materialdesign:animate="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="26dp"
        android:layout_marginBottom="26dp" />

    <com.gc.materialdesign.views.CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        materialdesign:check="true"
        android:layout_below="@+id/button"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <com.gc.materialdesign.views.Switch
        android:id="@+id/switchView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkBox"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <com.gc.materialdesign.views.Slider
        android:id="@+id/slider"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#1E88E5"
        materialdesign:max="50"
        materialdesign:min="0"
        android:layout_marginTop="29dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/switchView" />

    <com.gc.materialdesign.views.Slider
        android:id="@+id/slider2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#1E88E5"
        materialdesign:max="50"
        materialdesign:min="0"
        materialdesign:showNumberIndicator="true"
        android:layout_below="@+id/slider" />

</RelativeLayout>
MyActivity.java

public class MyActivity extends Activity {
    ButtonFlat buttonFlat = null;
    ButtonRectangle buttonRectangle = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        buttonFlat = (ButtonFlat)this.findViewById(R.id.buttonflat);
        buttonFlat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ColorSelector colorSelector = new ColorSelector(MyActivity.this,0,new ColorSelector.OnColorSelectedListener() {
                    @Override
                    public void onColorSelected(int color) {

                    }
                });
                colorSelector.show();
            }
        });

        buttonRectangle = (ButtonRectangle)this.findViewById(R.id.button);
        buttonRectangle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Dialog dialog = new Dialog(MyActivity.this,"Title","Message");
                dialog.show();
            }
        });
    }
}

スクリーンショット

2015-01-08_15_59_57_png.png
2015-01-08_16_00_04_png_と_2015-01-08_16_00_17_png.png
2015-01-08_16_00_17_png.png

不具合?

  • Switchとチェックボックスの色が変更できなく、緑色に固定になる
  • floatingActionButtonはiconDrawable属性が使えなく、アイコンが設定できない。

Githubをみてみてもいろいろ不具合があるらしく、活発に開発が行われているのでいずれ修正されるでしょう。
もしかしたら僕だけかな?

33
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?