はじめに

マテリアルデザインはシンプルでフラットなGoogleが提唱しているAndroidの新しいデザイン模様です。
Android開発でマテリアルデザインを取り込むのをサポートしているライブラリを導入してみます。

マテリアルデザインについては以下を参照ください
https://www.google.com/design/spec/material-design/introduction.html#

MaterialDesignLibraryについて

MaterialDesignLibraryはAndroidのマテリアルデザインをサポートしているライブラリです。
※starも現在4700ついてました

実際どういったライブラリかどうかは以下のデモアプリで確認できます
https://play.google.com/store/apps/details?id=com.gc.demomaterialdesign

MaterialDesignLibraryリポジトリ詳細は以下を確認ください
https://github.com/navasmdc/MaterialDesignLibrary

プロジェクトへMaterialDesignLibraryの取り込み

まずは導入するプロジェクトを作成してください。
プロジェクト直下へ移動して以下のコマンドでライブラリをgitのサブモジュールとして取り込みます。
※GitHubのリポジトリより直接ダウンロードして配置しても問題ありません

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

プロジェクトへMaterialDesignLibraryを読み込み

プロジェクトのapp/build.gradle(AndroidStudioではGradleScriptでModule: appのbuild.gradle)へ以下を追加します

repositories {
jcenter()
}

dependencies {
compile ‘com.github.navasmdc:MaterialDesign:1.5@aar’
}

※dependenciesはプロジェクト新規で存在しているため、compile構文を一行追加でOKです

ここまでで取り込み完了です

MaterialDesignLibraryのViewを使ってみる

レイアウトの外枠は以下を設置してください

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

上記のRelativeLayout内へボタンを配置してみます

<com.gc.materialdesign.views.ButtonFlat
                android:id="@+id/buttonflat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                android:text="Button" />

これでボタンが表示されればOKです。簡単にマテリアルデザインのビューを実装できました。
ボタンのイベントコールバックなどもAndroidデフォルトのボタンと変わらないので簡単です。

その他Viewの詳細についてはREADMEより確認してください
https://github.com/navasmdc/MaterialDesignLibrary

その他おすすめの備忘録

コメントを残す