/** * 设置标题的背景 * * @param resId */ public void setTitleDrawable(int resId) { if (resId == -1) { mMiddleButton.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(resId), null, null, null); return; } mMiddleButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); }
/** * 设置TopBarView 标题 * * @param title */ public void setTitle(String title) { if (TextUtils.isEmpty(title)) { mMiddleButton.setVisibility(View.INVISIBLE); return; } mMiddleButton.setText(title); mMiddleButton.setVisibility(View.VISIBLE); mMiddleButton.setOnClickListener(mClickListener); doSetTouchDelegate(); }
/** * 显示up 或者Down 的图标 * * @param up * @param arrow */ public void setMiddleBtnArrowUp(boolean up, boolean arrow) { if (mArrowUp == up && !arrow) { return; } mArrowUp = up; int id = R.drawable.common_top_bar_arrow_down; if (mArrowUp) { id = R.drawable.common_top_bar_arrow_up; } Drawable upDownDrawable = mContext.getResources().getDrawable(id); upDownDrawable.setBounds( 0, 0, upDownDrawable.getIntrinsicWidth(), upDownDrawable.getIntrinsicHeight()); mMiddleButton.setCompoundDrawablePadding(DensityUtil.dip2px(5.0F)); mMiddleButton.setCompoundDrawablesWithIntrinsicBounds(null, null, upDownDrawable, null); }
/** * 设置MiddleButton 的padding * * @param padding */ public void setMiddleBtnPadding(int padding) { if (mMiddleButton == null) { return; } mMiddleButton.setPadding(padding, 0, padding, 0); }