くらげになりたい。

くらげのようにふわふわ生きたい日曜プログラマなブログ。趣味の備忘録です。

AndroidStudioでAndroidBootstrap

ノンデザイナー御用達のAndroidBootstrapがいつのまにかGradle対応されていた。 これでAndroidStudio(Gradle)からでもらくらく利用できる!! その備忘録。

昔はgit submoduleとか使ってたなぁ。。。

dependenciesに追加

dependencies {
   compile 'com.beardedhen:androidbootstrap:+'
}

フォントファイルをassetsに配置

FontAwesomeのフォントファイルをダウンロードして配置する。

上のGitHubにもあるのでそこからダウンロード。

ダウンロードしたら以下な感じのassets配下に配置。

MyApp
├── MyApp.iml
├── app
│   └── src
│       └── main
│           ├── assets
│           │   └── fontawesome-webfont.ttf
│           ├── java
│           └── res

いざ使う!

ということで、ボタンのサンプル

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.beardedhen.androidbootstrap.BootstrapButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"
        bootstrap:bb_type="success"
        bootstrap:bb_size="small"
        bootstrap:bb_roundedCorners="true" />

</LinearLayout>

まずは、宣言にこいつをかく

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

BootstrapのButtonは「com.beardedhen.androidbootstrap.BootstrapButton」

そして、各種設定は「bootstrap:bb_xxx」で。

bootstrap:bb_type

ボタンのタイプと言うか色の指定。種類は以下。 - default, primary, success, info, warning, danger, link

どのタイプがどんなんかはここをみる - CSS · Bootstrap

bootstrap:bb_size

まんまサイズの指定。種類は以下。 - large, default, small, xsmall

bootstrapbutton:bb_roundedCorners="true"

角を丸くしますか?しませんか?

他にも

アイコンを表示するとかもある。

bootstrapbutton:bb_icon_left="fa-heart"
bootstrapbutton:bb_roundedCorners="true"

使えるアイコンはFont Awesome Cheatsheetを参照

以上!