From 87c093846b425bd9645e171d097e90c0a58e0279 Mon Sep 17 00:00:00 2001 From: shengqf <251877543@qq.com> Date: Thu, 1 Aug 2019 22:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shengqf/bottompw/MainActivity.kt | 20 ++++---- .../com/shengqf/view/bottom_pw/BottomPW.kt | 48 +++++++++---------- .../com/shengqf/view/bottom_pw/PwAdapter.kt | 10 ++-- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/shengqf/bottompw/MainActivity.kt b/app/src/main/java/com/shengqf/bottompw/MainActivity.kt index d49788d..253a33d 100644 --- a/app/src/main/java/com/shengqf/bottompw/MainActivity.kt +++ b/app/src/main/java/com/shengqf/bottompw/MainActivity.kt @@ -1,7 +1,6 @@ package com.shengqf.bottompw import android.os.Bundle -import android.support.v4.content.ContextCompat import android.support.v7.app.AppCompatActivity import android.widget.Toast import com.shengqf.view.bottom_pw.BottomPW @@ -20,19 +19,19 @@ class MainActivity : AppCompatActivity() { if (mBottomPW == null) { mBottomPW = BottomPW(this) .setList(mList) - .setPwPadding(10)//BottomPW的内边距,单位dp(默认是10dp) + .setPwPadding(10f)//BottomPW的内边距,单位dp(默认是10dp) .setCornerRadius(10)//圆角大小,单位dp(默认是10dp) - .setShowTitleTv(false)//是否显示列表上方的标题,默认不显示 - .setTitleStr("请选择")//列表上方的标题内容,默认为 - .setTitleHeight(49)//列表上方的标题高度,单位dp(默认是49dp) - .setTitleColor(ContextCompat.getColor(this@MainActivity, R.color.text_tips))//列表上方的标题字体颜色,默认是ContextCompat.getColor(mActivity, R.color.text_tips),text_tips:#999 + .setShowTitleTv(true)//是否显示列表上方的标题,默认不显示 + .setTitleStr("请选择")//列表上方的标题内容,默认为"请选择" + .setTitleHeight(49f)//列表上方的标题高度,单位dp(默认是49dp) + .setTitleColor(R.color.red)//列表上方的标题字体颜色,默认颜色是:#999999 .setTitleSize(16)//列表上方的标题字体大小,默认是16sp - .setItemHeight(49)//列表Item的高度,单位dp(默认是49dp) - .setItemTextColor(ContextCompat.getColor(this@MainActivity, R.color.text_primary))//列表Item的字体颜色,默认是ContextCompat.getColor(mActivity, R.color.text_primary),text_primary:#333 + .setItemHeight(49f)//列表Item的高度,单位dp(默认是49dp) + .setItemTextColor(R.color.blue)//列表Item的字体颜色,默认颜色是:#333333 .setItemTextSize(16)//列表Item的字体大小,默认是16sp .setShowCancelTv(true)//是否显示底部的cancel按钮,默认显示 - .setCancelHeight(49)//cancel按钮的高度,单位dp(默认是49dp) - .setCancelTextColor(ContextCompat.getColor(this@MainActivity, R.color.text_tips))//cancel按钮的字体颜色,默认是ContextCompat.getColor(mActivity, R.color.text_tips),text_tips:#999 + .setCancelHeight(49f)//cancel按钮的高度,单位dp(默认是49dp) + .setCancelTextColor(R.color.text_primary)//cancel按钮的字体颜色,默认颜色是:#999999 .setCancelTextSize(16)//cancel按钮字体大小,默认是16sp .setCancelTextStr("取消")//默认文字是"取消" .setOnPwItemClickListener(getOnPwItemClickListener())//列表Item点击事件 @@ -58,4 +57,5 @@ class MainActivity : AppCompatActivity() { } } } + } diff --git a/view/src/main/java/com/shengqf/view/bottom_pw/BottomPW.kt b/view/src/main/java/com/shengqf/view/bottom_pw/BottomPW.kt index 03fa848..c4b6c5e 100644 --- a/view/src/main/java/com/shengqf/view/bottom_pw/BottomPW.kt +++ b/view/src/main/java/com/shengqf/view/bottom_pw/BottomPW.kt @@ -40,21 +40,21 @@ class BottomPW(activity: Activity) { private var mOnPwItemClickListener: OnPwItemClickListener? = null private var mOnPwDismissListener: OnPwDismissListener? = null - private var mPwPadding: Int = dp2px(10f)//Pw默认padding10dp - private var mCornerRadius: Int = dp2px(10f)//圆角默认大小10dp - private var mShowTitleTv = false //是否显示标题 - private var mTitleStr: String = "请选择" //标题字体内容 - private var mTitleHeight: Int = dp2px(49f) //title的行高 - private var mTitleColor: Int = ContextCompat.getColor(mActivity, R.color.text_tips) //title字体颜色 - private var mTitleSize: Int = 16 //title字体大小 - private var mItemHeight: Int = dp2px(49f) //列表Item的行高 - private var mItemTextColor: Int = ContextCompat.getColor(mActivity, R.color.text_primary) //列表Item的字体颜色 - private var mItemTextSize: Int = 16 //列表Item的字体大小 - private var mShowCancelTv = true //是否显示底部的取消 - private var mCancelHeight: Int = dp2px(49f) //取消字体的行高 - private var mCancelTextColor: Int = ContextCompat.getColor(mActivity, R.color.text_tips) //取消字体的颜色 - private var mCancelTextSize: Int = 16 //取消字体的大小 - private var mCancelTextStr: String = "取消" //取消字体的内容 + private var mPwPadding: Float = 10f//Pw默认padding,,默认为10dp + private var mCornerRadius: Int = 10//圆角大小,默认为10dp + private var mShowTitleTv = false //是否显示标题,默认不显示 + private var mTitleStr: String = "请选择" //标题字体内容,默认为"请选择" + private var mTitleHeight: Float = 49f //title的行高,默认为49dp + private var mTitleColor: Int = R.color.text_tips //title字体颜色 + private var mTitleSize: Int = 16 //title字体大小,默认是16sp + private var mItemHeight: Float = 49f //列表Item的行高,默认是49dp + private var mItemTextColor: Int = R.color.text_primary //列表Item的字体颜色 + private var mItemTextSize: Int = 16 //列表Item的字体大小,默认是16sp + private var mShowCancelTv = true //是否显示底部的取消,默认显示 + private var mCancelHeight: Float = 49f //底部取消按钮的行高,默认49dp + private var mCancelTextColor: Int = R.color.text_tips //取消字体的颜色 + private var mCancelTextSize: Int = 16 //取消字体的大小,默认是16sp + private var mCancelTextStr: String = "取消" //取消字体的内容,默认为"取消" //设置列表数据源 fun setList(list: ArrayList): BottomPW { @@ -75,7 +75,7 @@ class BottomPW(activity: Activity) { return this } - fun setPwPadding(pwPadding: Int): BottomPW { + fun setPwPadding(pwPadding: Float): BottomPW { this.mPwPadding = pwPadding return this } @@ -95,7 +95,7 @@ class BottomPW(activity: Activity) { return this } - fun setTitleHeight(titleHeight: Int): BottomPW { + fun setTitleHeight(titleHeight: Float): BottomPW { this.mTitleHeight = titleHeight return this } @@ -110,7 +110,7 @@ class BottomPW(activity: Activity) { return this } - fun setItemHeight(itemHeight: Int): BottomPW { + fun setItemHeight(itemHeight: Float): BottomPW { this.mItemHeight = itemHeight return this } @@ -130,7 +130,7 @@ class BottomPW(activity: Activity) { return this } - fun setCancelHeight(cancelHeight: Int): BottomPW { + fun setCancelHeight(cancelHeight: Float): BottomPW { this.mCancelHeight = cancelHeight return this } @@ -169,7 +169,7 @@ class BottomPW(activity: Activity) { private fun initView() { mContentView = LayoutInflater.from(mActivity).inflate(R.layout.layout_pw_bottom, null) //pw内边距 - mContentView.setPadding(mPwPadding, mPwPadding, mPwPadding, mPwPadding) + mContentView.setPadding(dp2px(mPwPadding), dp2px(mPwPadding), dp2px(mPwPadding), dp2px(mPwPadding)) with(mContentView) { //设置圆角 @@ -180,9 +180,9 @@ class BottomPW(activity: Activity) { if (mShowTitleTv) { view_stub.inflate() title_tv.text = mTitleStr - title_tv.layoutParams.height = mTitleHeight + title_tv.layoutParams.height = dp2px(mTitleHeight) title_tv.textSize = mTitleSize.toFloat() - title_tv.setTextColor(mTitleColor) + title_tv.setTextColor(ContextCompat.getColor(mActivity,mTitleColor)) } //列表 @@ -192,9 +192,9 @@ class BottomPW(activity: Activity) { //取消按钮 cancel_tv.visibility = if (mShowCancelTv) View.VISIBLE else View.GONE - cancel_tv.setTextColor(mCancelTextColor) + cancel_tv.setTextColor(ContextCompat.getColor(mActivity,mCancelTextColor)) cancel_tv.textSize = mCancelTextSize.toFloat() - cancel_tv.layoutParams.height = mCancelHeight + cancel_tv.layoutParams.height = dp2px(mCancelHeight) cancel_tv.text = mCancelTextStr cancel_tv.setOnClickListener { mPopupWindow.dismiss() diff --git a/view/src/main/java/com/shengqf/view/bottom_pw/PwAdapter.kt b/view/src/main/java/com/shengqf/view/bottom_pw/PwAdapter.kt index f7a3a57..ec4b388 100644 --- a/view/src/main/java/com/shengqf/view/bottom_pw/PwAdapter.kt +++ b/view/src/main/java/com/shengqf/view/bottom_pw/PwAdapter.kt @@ -28,11 +28,11 @@ class PwAdapter constructor(context: Context) : RecyclerView.Adapter