安卓平台下使用bootstrap

来源:互联网 发布:廉价口红知乎 编辑:程序博客网 时间:2024/06/14 10:39

   之前在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>

原创粉丝点击