第一步:Moudle加入Bootstrap依赖库(目前提供版本2.3.2,如果提示不成功改成2.0.1版本)
implementation 'com.beardedhen:androidbootstrap:2.3.2'
implementation 'com.beardedhen:androidbootstrap:2.0.1'
第二步:在java包下新建一个类,在Superclass下查找Application,并继承这个类,选择android.app.Application点击确定,并添加一下代码:
import android.app.Application; import com.beardedhen.androidbootstrap.TypefaceProvider; public class Boot extends Application { @Override public void onCreate() { super.onCreate(); TypefaceProvider.registerDefaultIconSets(); } }
第三步:清单文件里application下添加android:name=".Boot"代码
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didu.myapplication"> <uses-permission android:name="android.permission.INTERNET" /> <application android:name=".Boot" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Index"></activity> </application> </manifest>
第四步:layout布局文件下的.xml里添加
原Button代码:
<Button android:id="@+id/btn000" android:layout_width="match_parent" android:layout_height="wrap_content" />
现Bootstrap代码:
app:bootstrapBrand相当于HTML里的class,接样式名"success",app:roundedCorners="true""false"是否圆角
<com.beardedhen.androidbootstrap.BootstrapButton app:bootstrapBrand="success" app:roundedCorners="true" android:id="@+id/btn000" android:layout_width="match_parent" android:layout_height="wrap_content" />