if (mToolbar != null) { val mMenu = mToolbar!!.menu if (mMenu.javaClass.simpleName.contentEquals("MenuBuilder")) { try { val method = mMenu.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE) method.isAccessible = true method.invoke(mMenu, true) } catch (e: Exception) { e.printStackTrace() } } }
用代码动态调整MaxWidth
1 2 3 4 5 6 7 8 9
val tw = helper.getView(R.id.tv_nickname) as TextView val cw = helper.getView(R.id.cl_history) as ConstraintLayout val twDate = helper.getView(R.id.tv_btn) as TextView cw.post { val newMaxWidth = cw.width - DensityUtil.dp2px(72f) - twDate.width if (newMaxWidth > 0) { tw.maxWidth = newMaxWidth } }