安卓平台下使用bootstrap

   之前在web下已经习惯了使用bootstrap,轻易就可以调出不错的样式,后来发现原来安卓平台下也可以用bootstrap,所以用bootstrap写了一个小demo

   首先需要引入依赖包

  

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

  然后需要覆盖application类,bootstrap需要通过这个类注册icon

public class SampleApplication extends Application{

    private static Application instance;

    public static Application getAplication(){
        return instance;
    }

    public static Context getContext(){
        return instance.getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance=this;
        TypefaceProvider.registerDefaultIconSets();
    }
}

然后就可以开始使用bootstrap了,用法和web端很类似。详细的请看文档https://github.com/Bearded-Hen/Android-Bootstrap/wiki/Awesome-Text-View

下面是用bootstrap写的登录界面

<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="layout.LoginFragment">

    <com.beardedhen.androidbootstrap.BootstrapEditText
        android:layout_width="200dp"
        android:layout_height="40dp"
        app:bootstrapSize="xl"
        app:bootstrapBrand="success"
        app:roundedCorners="true"
        android:textSize="15sp"
        android:cursorVisible="false"
        android:gravity="center"
        android:id="@+id/username"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/password"
        android:layout_alignStart="@+id/password"
        android:layout_marginTop="49dp" />

    <com.beardedhen.androidbootstrap.BootstrapButton
        android:layout_width="200dp"
        android:layout_height="wrap_content"

        android:onClick="login"
        app:bootstrapBrand="success"
        app:bootstrapSize="lg"
        app:buttonMode="regular"
        app:showOutline="false"
        app:roundedCorners="true"

        app:bootstrapText="{fa_user}           登录              "
        android:id="@+id/login"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/register"
        android:layout_alignStart="@+id/register" />

    <com.beardedhen.androidbootstrap.BootstrapButton
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="@string/register"
        android:onClick="register"
        app:bootstrapText="{fa_lock}           注册              "
        app:bootstrapBrand="primary"
        app:bootstrapSize="lg"
        app:buttonMode="regular"
        app:showOutline="false"
        app:roundedCorners="true"
        android:id="@+id/register"
        android:layout_below="@+id/login"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="44dp" />

    <com.beardedhen.androidbootstrap.BootstrapEditText
        android:layout_width="200dp"
        android:layout_height="40dp"
        app:bootstrapSize="xl"
        app:bootstrapBrand="success"
        app:roundedCorners="true"
        android:textSize="15sp"
        android:cursorVisible="false"
        android:gravity="center"
        android:id="@+id/password"
        android:layout_marginTop="49dp"
        android:layout_below="@+id/username"
        android:layout_alignLeft="@+id/login"
        android:layout_alignStart="@+id/login" />

    <com.beardedhen.androidbootstrap.BootstrapLabel
        android:layout_width="100dp"
        android:layout_height="25dp"
        app:bootstrapBrand="success"
        app:bootstrapHeading="h6"
        app:roundedCorners="true"
        android:text="登录成功"
        android:layout_marginTop="26dp"
        android:id="@+id/successLabel"
        android:layout_below="@+id/register"
        android:layout_centerHorizontal="true"
        android:visibility="invisible"/>

    <com.beardedhen.androidbootstrap.BootstrapLabel
        android:layout_width="100dp"
        android:layout_height="25dp"
        app:bootstrapBrand="danger"
        app:bootstrapHeading="h6"
        app:roundedCorners="true"
        android:text="登录失败"
        android:layout_marginTop="26dp"
        android:id="@+id/failLabel"
        android:layout_below="@+id/register"
        android:layout_centerHorizontal="true"
        android:visibility="invisible">

    </com.beardedhen.androidbootstrap.BootstrapLabel>

</RelativeLayout>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值