怎么说呢 如果有一个这样的工具 既可以灵活配置 又全面丰富的老少咸宜的库是多么的美好的存在。答案是:不存在的。但是又有多少人放弃了?都在为之努力。不正是这种开源精神才能让互联网迸发活波生机吗?身为互联网浪潮中的一员,也需要时刻记着,学无止境,再一次一次次的科技浪潮中,只有勇于投身当中者才有绝地求生的可能,那些原地踏步者只有人仰马翻的结局,从15年跻身互联网行列当中,有幸见证洛基亚的衰败,站在移动开发的风口浪尖。这是一个幸运的年代,也是一个不幸的年代。从AsyncHttp到Xutil 到 Volley 到 Retrofit 再到Nohttp 再到现在的Novate 框架学了又写,当听到别人说:Volley?已经被淘汰了。我也只是心里叫苦。此时才能理解什么叫做“不在乎天长地久,只在乎你曾经拥有。”当然也有很优秀的项目 比如说剪纸堆 (heruoxin),看了他的产品你会发现一片新天地。在感叹作者扎实的功底同时,你也绝不会想使用其中的代码,因为两个字“原生”。此话不带有任何有色字眼,只是感叹作者的扎实功底。有时候框架多得让人眼花缭乱只时,原生也不失为一个好的方法。
以上闲谈可忽略
-----------------------------------------------------一个漂亮的分割线-----------------------------------------------------------
现在进入正题 由于作者只是给了简单的官网和一些简单得功能简介,所以最好的方法还是快去看作者的源码吧。
最好下载下来(本地打开总比在github快),再使用Sublime Text3打开,为什么用这个是因为它能打开文件夹,因为可以查看目录结构,至少我是这么认为的。
这边在库引用中合并了values.xml ,作者的注释以及优秀的命名方式 看了就很明了le
为避免打开项目失败 我会一个个做解释 直接粘贴一下代码 在manifest中一定要引用哦
如下配置基本解决theme的问题
下面简单介绍以下使用方法
QMUITipDialog
var dialog: QMUITipDialog? = null
fun showError(msg: String) {
dialog?.dismiss()
dialog = QMUITipDialog.Builder(this)
.setTipWord(msg)
.setIconType(QMUITipDialog.Builder.ICON_TYPE_FAIL)
.create()
dialog?.show()
dimiss()
}
fun dimiss() {
ShopApp.instance.mainHandler.postDelayed({
dialog?.dismiss()
}, 500)
}
fun complete(msg: String) {
dialog?.dismiss()
dialog = QMUITipDialog.Builder(this)
.setTipWord(msg)
.setIconType(QMUITipDialog.Builder.ICON_TYPE_SUCCESS)
.create()
dialog?.show()
dimiss()
}
fun loadingDialog(msg: String) {
dialog?.dismiss()
dialog = QMUITipDialog.Builder(this)
.setTipWord(msg)
.setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
.create()
dialog?.show()
}
QMUIGroupListView
val acount_safe = bottom_list.createItemView(getString(R.string.acount_safe)).apply { accessoryType = QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON }
val my_invite = bottom_list.createItemView(getString(R.string.my_invite)).apply { accessoryType = QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON }
val faq = bottom_list.createItemView(getString(R.string.faq)).apply { accessoryType = QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON }
val feedback = bottom_list.createItemView(getString(R.string.feedback)).apply { accessoryType = QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON }
val about_us = bottom_list.createItemView(getString(R.string.about_us)).apply { accessoryType = QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON }
QMUIGroupListView.newSection(context)
.setUseTitleViewForSectionSpace(false)
.addItemView(merchant_msg, MyOnclickLisetner("merchant_msg"))
.addItemView(my_msg, MyOnclickLisetner("my_msg"))
.addItemView(acount_safe, MyOnclickLisetner("acount_safe"))
.addItemView(my_invite, MyOnclickLisetner("my_invite"))
.addItemView(faq, MyOnclickLisetner("faq"))
.addItemView(feedback, MyOnclickLisetner("feedback"))
.addItemView(about_us, MyOnclickLisetner("about_us"))
.addTo(bottom_list)
QMUIDialog
private fun showAutoDialog(message: String) {
val builder = QMUIDialog.MessageDialogBuilder(this@BarterPayActivity)
builder.setTitle(R.string.tip)
.setMessage(message)
.addAction(0, R.string.cancel, QMUIDialogAction.ACTION_PROP_NEGATIVE) { dialog, index -> dialog.dismiss() }
.addAction(0, R.string.confirm, QMUIDialogAction.ACTION_PROP_POSITIVE) { dialog, index ->
barterPayPresenter.getOrder(barterPayParam)
dialog.dismiss()
}
.show()
}
QMUIListPopup
private fun showMenuPop() {
if (mPopupWindow == null) {
val mGoodArray = resources.getStringArray(R.array.merchant_barter_type)
mPopupWindow = QMUIListPopup(this@BarterConsumDetailActivity,
QMUIPopup.DIRECTION_BOTTOM,
ArrayAdapter(this@BarterConsumDetailActivity, R.layout.simple_list_item, mGoodArray))
mPopupWindow?.create(QMUIDisplayHelper.dp2px(this@BarterConsumDetailActivity, 130),
QMUIDisplayHelper.dp2px(this@BarterConsumDetailActivity, 200)) { _, _, position, _ ->
launchActivity {
putExtra("type", position + 1)
putExtra("type_name", mGoodArray[position])
}
mPopupWindow?.dismiss()
}
}
mPopupWindow?.setAnimStyle(QMUIPopup.ANIM_GROW_FROM_RIGHT)
mPopupWindow?.show(topbar.find(R.id.head_right))
}
QMUIPullRefreshLayout
mPullRefreshLayout.setOnPullListener(this)
QMUITopBar
topbar.addRightImageButton(R.drawable.more_point, R.id.head_right).onClick {
showMenuPop()
}
沉浸式
mCollapsingTopBarLayout.setScrimUpdateListener(object : ValueAnimator.AnimatorUpdateListener {
override fun onAnimationUpdate(animation: ValueAnimator) {
topbar?.background?.alpha = "${animation.animatedValue}".toInt()
}
})
topbar.background.alpha = 0
mQMUIAppBarLayout.addOnOffsetChangedListener(object : AppBarStateChangeListener() {
override fun onStateChanged(appBarLayout: AppBarLayout, state: AppBarStateChangeListener.State) {
Log.d("STATE", state.name)
if (state == AppBarStateChangeListener.State.EXPANDED) {
//展开状态
mPullRefreshLayout.setEnabled(true)
mainCity?.apply {
setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(context, R.drawable.icon_pull_white), null)
textColor = Color.parseColor("#ffffff")
}
topbar.find(R.id.main_head_ll).setBackgroundResource(R.drawable.shape_color_white)
} else if (state == AppBarStateChangeListener.State.COLLAPSED) {
//折叠状态
mPullRefreshLayout.setEnabled(false)
mainCity?.apply {
setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(context, R.drawable.icon_choice_pull), null)
textColor = Color.parseColor("#333333")
}
topbar.find(R.id.main_head_ll).setBackgroundResource(R.drawable.shape_color_gray)
} else {
//中间状态
mPullRefreshLayout.setEnabled(false)
}
}
})
//以下为AppBarStateChangeListener的源码
public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
public enum State {
EXPANDED,
COLLAPSED,
IDLE
}
private State mCurrentState = State.IDLE;
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
if (i == 0) {
if (mCurrentState != State.EXPANDED) {
onStateChanged(appBarLayout, State.EXPANDED);
}
mCurrentState = State.EXPANDED;
} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
if (mCurrentState != State.COLLAPSED) {
onStateChanged(appBarLayout, State.COLLAPSED);
}
mCurrentState = State.COLLAPSED;
} else {
if (mCurrentState != State.IDLE) {
onStateChanged(appBarLayout, State.IDLE);
}
mCurrentState = State.IDLE;
}
}
public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
}
其他工具类
QMUIStatusBarHelper.setStatusBarLightMode(this)
//QMUIStatusBarHelper.translucent(this, Color.parseColor("#ffffff"))
QMUIStatusBarHelper.setStatusBarLightMode(this)
关注公众号领取更多干货