(十) 盘古UI,详情小标题副标题的实现,方便快速开发详情PanguFormTitle!
盘古UI,较为全面的自定义UI框架,帮助你绝对的快速开发!(长期维护中)
控件位置:
com.smart.pangu_ui_lib.widget.PanguFormTitle
demo地址,点击查看github
详情|表单的小标题
可以在详情或者表单的页面使用这个小标题!
1, 样例展示图
2, 使用说明
1,布局
<com.smart.pangu_ui_lib.widget.PanguFormTitle
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:pgft_icon_right="@mipmap/ic_arrow_right"
app:pgft_mid_title="中间内容"
app:pgft_must="true"
android:id="@+id/pg_ftitle"
app:pgft_show_line="false"
app:pgft_show_right_title="visiable"
app:pgft_title="标题" />
2,方法使用
mPgFtitle.setOnRightClick(new View.OnClickListener() {
@Override
public void onClick(View v) {
showToast("点击了右标题");
}
});
mPgFtitle.setOnRightIconClick(new View.OnClickListener() {
@Override
public void onClick(View v) {
showToast("点击了右图标");
}
});
3, 方法和属性说明
attr属性 | 方法 method | 介绍 introduction |
---|---|---|
pgft_title_size | setTitleSize(int titleSize) | 设置标题字体的大小 |
pgft_title_color | setTitleColor(int titleColor) | 设置标题的颜色 |
pgft_title_text_style | setTitleTextStyle(int typeface) | 设置标题样式,typeface Typeface.BOLD 加粗 Typeface.NORMAL 正常 |
pgft_title | setTitle(String title) setTitle(CharSequence title) | 设置标题名称 |
pgft_padding_start | setPaddingStart(float paddingStart) | paddingStart |
pgft_right_title | setRightTitle(String title) | 设置右侧标题 |
pgft_must | setIsMust(boolean must) | 是否是必填 |
pgft_show_line | showLine(boolean showLine) | 显示下面的线 |
pgft_background | setBackgroundColorFt(@ColorInt int color) | 设置背景颜色 |
pgft_show_right_title | setShowRight(boolean has) | 是否显示右侧标题,默认是"更多"文字 |
pgft_icon_right | setRightRIcon(@DrawableRes int resId) | 设置右侧图标 , 0 不显示 |
pgft_mid_title | setMidText(String midTitle) | 设置控件中间的文字 |
pgft_mid_textColor | setMidTextColor(int midTitleTextColor) | 设置中间文字的字体颜色 |
---- | LinearLayout getMidContentView() | 获取中间的线性布局,可以自定义布局内容 |
---- | setOnRightClick(OnClickListener listener) | 右侧标题的点击事件 |
---- | setOnRightIconClick(OnClickListener listener) | 右侧图标的点击事件 |
4, 代码和方法简析
public class PanguFormTitle extends BaseView {
private LinearLayout mLlRoot;
private View mViewLine;
private TextView mTvMore;
private ImageView mIvRight;
private LinearLayout mLlMidContent;
private RelativeLayout mRlContent;
private TextView mTvName;
private TextView mTvMust;
private int showRightTitle;
private float paddingStart;
private String midTitle;
private int midTitleTextColor;
private int backgroundColor;
private String title;
private String rightTitle;//右侧标题
private int iconRight;
private int titleTextStyle;//title的加粗
private int titleColor;//标题颜色
private int titleSize;//标题字体大小
private boolean must;//必填红星
private boolean showLine;//是否展示下面的线
@Override
protected int getLayoutId() {
return R.layout.pangu_formtitle;
}
public PanguFormTitle(Context context) {
super(context);
}
public PanguFormTitle(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
mLlRoot = findViewById(R.id.ll_root);
mViewLine = findViewById(R.id.view_line);
mTvMore = findViewById(R.id.tv_more);
mIvRight = findViewById(R.id.iv_right);
mLlMidContent = findViewById(R.id.ll_mid_content);
mRlContent = findViewById(R.id.rl_content);
mTvName = findViewById(R.id.tv_name);
mTvMust = findViewById(R.id.tv_must);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PanguFormTitle
, defStyleAttr, 0);
//名称
title = typedArray.getString(R.styleable.PanguFormTitle_pgft_title);
rightTitle = typedArray.getString(R.styleable.PanguFormTitle_pgft_right_title);
must = typedArray.getBoolean(R.styleable.PanguFormTitle_pgft_must, false);
showLine = typedArray.getBoolean(R.styleable.PanguFormTitle_pgft_show_line, false);
backgroundColor = typedArray.getColor(R.styleable.PanguFormTitle_pgft_background,
Color.TRANSPARENT);
showRightTitle = typedArray.getInt(R.styleable.PanguFormTitle_pgft_show_right_title, View.GONE);
//中间
midTitle = typedArray.getString(R.styleable.PanguFormTitle_pgft_mid_title);
midTitleTextColor = typedArray.getColor(R.styleable.PanguFormTitle_pgft_mid_textColor,
Color.BLACK);
//右侧图标
iconRight = typedArray.getResourceId(R.styleable.PanguFormTitle_pgft_icon_right, 0);
paddingStart = typedArray.getDimension(R.styleable.PanguFormTitle_pgft_padding_start, PhoneHelper.dip2px(mContext, 12));
//title的加粗
titleTextStyle = typedArray.getInt(R.styleable.PanguFormTitle_pgft_title_text_style, Typeface.BOLD);
//标题的颜色
titleColor = typedArray.getInteger(R.styleable.PanguFormTitle_pgft_title_color, Color.parseColor("#30353D"));
//标题字体大小
titleSize = typedArray.getDimensionPixelSize(R.styleable.PanguFormTitle_pgft_title_size, PhoneHelper.sp2px(getContext(), 14));
typedArray.recycle();
init();
}
private void init() {
//设置标题名称
setTitle(title);
setIsMust(must);
setBackgroundColorFt(backgroundColor);
showLine(showLine);
setRightTitle(rightTitle);
setRightRIcon(iconRight);
showRightTitle(showRightTitle);
setPaddingStart(paddingStart);
setTitleTextStyle(titleTextStyle);
//标题的颜色
setTitleColor(titleColor);
setTitleSize(titleSize);
setMidText(midTitle);
setMidTextColor(midTitleTextColor);
}
/**
* 设置中间文字的字体颜色
*
* @param midTitleTextColor 颜色值
*/
public void setMidTextColor(int midTitleTextColor) {
this.midTitleTextColor = midTitleTextColor;
LinearLayout midContentView = getMidContentView();
if (midContentView != null && midContentView.getChildCount() > 0 && midContentView.getChildAt(0) instanceof TextView) {
TextView childAt = (TextView) midContentView.getChildAt(0);
childAt.setTextColor(midTitleTextColor);
}
}
/**
* 设置控件中间的文字
*
* @param midTitle
*/
public void setMidText(String midTitle) {
TextView tv2 = new TextView(mContext);
tv2.setText(midTitle);
tv2.setTextSize(14);
tv2.setTextColor(midTitleTextColor);
getMidContentView().removeAllViews();
getMidContentView().addView(tv2);
}
/**
* paddingStart
*
* @param paddingStart
*/
public void setPaddingStart(float paddingStart) {
mRlContent.setPadding((int) paddingStart, PhoneHelper.dip2px(mContext, 9), PhoneHelper.dip2px(mContext, 12), PhoneHelper.dip2px(mContext, 9));
}
/**
* 展示右侧标题
*
* @param showRightTitle {@link View#VISIBLE}{@link View#INVISIBLE}{@link View#GONE}
*/
public void showRightTitle(int showRightTitle) {
if (mTvMore != null)
mTvMore.setVisibility(showRightTitle);
}
/**
* 获取中间的线性布局,可以自定义布局内容
*
* @return LinearLayout
*/
public LinearLayout getMidContentView() {
return mLlMidContent;
}
/**
* 显示下面的线
*
* @param showLine
*/
public void showLine(boolean showLine) {
if (mViewLine != null) {
mViewLine.setVisibility(showLine ? VISIBLE : GONE);
}
}
/**
* 设置背景颜色
*
* @param color
*/
public void setBackgroundColorFt(@ColorInt int color) {
if (mLlRoot != null) {
mLlRoot.setBackgroundColor(color);
}
}
/**
* 设置标题名称
*
* @param title
*/
public void setTitle(String title) {
if (mTvName != null) {
mTvName.setText(title);
}
}
/**
* 设置标题名称
*
* @param title
*/
public void setTitle(CharSequence title) {
if (mTvName != null) {
mTvName.setText(title);
}
}
/**
* 设置标题样式
*
* @param typeface Typeface.BOLD 加粗 Typeface.NORMAL 正常
*/
public void setTitleTextStyle(int typeface) {
if (mTvName != null) {
mTvName.setTypeface(Typeface.defaultFromStyle(typeface));
}
}
/**
* 设置标题字体的大小
*
* @param titleSize
*/
public void setTitleSize(int titleSize) {
mTvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
}
/**
* 设置标题的颜色
*
* @param titleColor
*/
public void setTitleColor(int titleColor) {
if (mTvName != null) {
mTvName.setTextColor(titleColor);
}
}
/**
* 是否是必填
*
* @param must
*/
public void setIsMust(boolean must) {
if (mTvMust != null) {
mTvMust.setVisibility(must ? VISIBLE : GONE);
}
}
/**
* 是否显示右侧标题,默认是"更多"文字
*
* @param has
*/
public void setShowRight(boolean has) {
mTvMore.setVisibility(has ? VISIBLE : GONE);
}
/**
* 设置右侧标题
*
* @param title 标题
*/
public void setRightTitle(String title) {
if (mTvMore != null) {
mTvMore.setText(TextUtils.isEmpty(title) ? "更多>" : title);
}
}
/**
* 右侧标题的点击事件
*
* @param listener 监听
*/
public void setOnRightClick(OnClickListener listener) {
mTvMore.setOnClickListener(listener);
}
/**
* 设置右侧图标 , 0 不显示
*
* @param resId 资源id
*/
public void setRightRIcon(@DrawableRes int resId) {
if (mIvRight != null) {
if (resId != 0) {
mIvRight.setVisibility(VISIBLE);
mIvRight.setImageResource(resId);
} else {
mIvRight.setVisibility(GONE);
}
}
}
/**
* 右侧图标的点击事件
*
* @param listener 监听
*/
public void setOnRightIconClick(OnClickListener listener) {
mIvRight.setOnClickListener(listener);
}
}
5, 获取地址
demo地址,点击查看github
欢迎您扫码安装体验demo