在决定使用XUI前,你必须明确的一点是,此框架给出的是一整套UI的整体解决方案,如果你只是想使用其中的几个控件,那大可不必引入如此庞大的一个UI库,Github上会有更好的组件库。如果你是想拥有一套可以定制的、统一的UI整体解决方案的话,那么你就继续往下看吧!

添加Gradle依赖

Android原生与vue 交互 android原生ui_ide

1.先在项目根目录的 build.gradle 的 repositories 添加:

allprojects{
repositories{
...
maven{url"https://jitpack.io"}}
}

2.然后在dependencies添加:

dependencies{
...
//androidx项目
implementation'com.github.xuexiangjys:XUI:1.0.9'implementation'androidx.appcompat:appcompat:1.1.0'implementation'androidx.recyclerview:recyclerview:1.0.0'
implementation'com.google.android.material:material:1.1.0-alpha10'implementation'com.github.bumptech.glide:glide:4.8.0'}
【注意】如果你的项目目前还未使用androidx,请使用如下配置:dependencies{
...
//support项目
implementation'com.github.xuexiangjys:XUI:1.0.9-support'implementation'com.android.support:appcompat-v7:28.0.0'implementation'com.android.support:recyclerview-v7:28.0.0'implementation'com.android.support:design:28.0.0'implementation'com.github.bumptech.glide:glide:4.8.0'}

初始化XUI设置

1.在Application最顶部初始化设置(必须)XUI.init(this);//初始化UI框架

XUI.debug(true);//开启UI框架调试日志

2.调整应用的基础主题(必须)必须设置应用的基础主题,否则组件将无法正常使用!必须保证所有用到XUI组件的窗口的主题都为XUITheme的子类,这非常重要!!!

基础主题类型:大平板(10英寸, 240dpi, 1920*1200):XUITheme.Tablet.Big

小平板(7英寸, 320dpi, 1920*1200):XUITheme.Tablet.Small

手机(4.5英寸, 320dpi, 720*1280):XUITheme.Phone

@color/colorPrimary
@color/colorPrimaryDark
@color/colorAccent
当然也可以在Activity刚开始时调用如下代码动态设置主题@Override
protectedvoidonCreate(BundlesavedInstanceState){
XUI.initTheme(this);
super.onCreate(savedInstanceState);
...
}

3.调整字体库(对字体无要求的可省略)

(1)设置你需要修改的字体库路径(assets下)//设置默认字体为华文行楷,这里写你的字体库
XUI.getInstance().initFontStyle("fonts/hwxk.ttf");
(2)在项目的基础Activity中加入如下代码注入字体.@Override
protectedvoidattachBaseContext(ContextnewBase){
//注入字体
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

混淆配置

由于没有使用任何反射,无需代码混淆