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

2.然后在dependencies添加:

  1. ...
  2. //androidx项目
  3. implementation 'com.github.xuexiangjys:XUI:1.0.9'
  4. implementation 'androidx.appcompat:appcompat:1.1.0'
  5. implementation 'androidx.recyclerview:recyclerview:1.0.0'
  6. }

【注意】如果你的项目目前还未使用androidx,请使用如下配置:

  1. XUI.init(this); //初始化UI框架
  2. XUI.debug(true); //开启UI框架调试日志

2.调整应用的基础主题(必须)

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

基础主题类型:

  • 大平板(10英寸, 240dpi, 1920*1200):XUITheme.Tablet.Big

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

当然也可以在Activity刚开始时调用如下代码动态设置主题

  1. @Override
  2. XUI.initTheme(this);
  3. ...
  4. }

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

(1)设置你需要修改的字体库路径(assets下)

  1. @Override
  2. protected void attachBaseContext(Context newBase) {
  3. //注入字体
  4. super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
  5. }

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