Closed Zhao-Yan-Yan closed 3 years ago
版本 3.1.5
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<com.lihang.ShadowLayout
android:id="@+id/shadow_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/dp_15"
android:paddingTop="@dimen/dp_10"
android:paddingRight="@dimen/dp_15"
android:paddingBottom="@dimen/dp_10"
app:hl_cornerRadius="@dimen/dp_5"
app:hl_layoutBackground="#FF0000"
app:hl_shapeMode="pressed">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/white"
android:textSize="@dimen/sp_14"
tools:text="hello" />
</com.lihang.ShadowLayout>
</FrameLayout>
class ShadowButton : FrameLayout {
private val viewBinding = WidgetShadowButtonBinding.inflate(LayoutInflater.from(context), this, true)
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
val ta = context.obtainStyledAttributes(attrs, R.styleable.ShadowButton, defStyleAttr, defStyleRes)
val shadowButtonText = ta.getString(R.styleable.ShadowButton_shadow_button_text)
val shadowButtonTextColor = ta.getColor(R.styleable.ShadowButton_shadow_button_textColor, Color.TRANSPARENT)
val shadowButtonBackground = ta.getColor(R.styleable.ShadowButton_shadow_button_background, Color.TRANSPARENT)
val shadowButtonBackgroundTrue =
ta.getColor(R.styleable.ShadowButton_shadow_button_background_true, ColorUtils.setAlphaComponent(Color.GRAY, 0.8f))
val shadowButtonCornerRadius = ta.getDimensionPixelSize(R.styleable.ShadowButton_shadow_button_cornerRadius, 5.dp)
val shadowButtonPaddingLeft = ta.getDimensionPixelSize(R.styleable.ShadowButton_shadow_button_paddingLeft, 15.dp)
val shadowButtonPaddingTop = ta.getDimensionPixelSize(R.styleable.ShadowButton_shadow_button_paddingTop, 10.dp)
val shadowButtonPaddingRight = ta.getDimensionPixelSize(R.styleable.ShadowButton_shadow_button_paddingRight, 15.dp)
val shadowButtonPaddingBottom = ta.getDimensionPixelSize(R.styleable.ShadowButton_shadow_button_paddingBottom, 10.dp)
ta.recycle()
setTextColor(shadowButtonTextColor)
setText(shadowButtonText)
setLayoutBackgroundColor(shadowButtonBackground)
setLayoutBackgroundTrueColor(shadowButtonBackgroundTrue)
setCornerRadius(shadowButtonCornerRadius)
setInnerPadding(
shadowButtonPaddingLeft,
shadowButtonPaddingTop,
shadowButtonPaddingRight,
shadowButtonPaddingBottom
)
}
fun setText(text: String?) {
viewBinding.textView.text = text
}
fun setTextColor(color: Int) {
viewBinding.textView.setTextColor(color)
}
fun setInnerPadding(l: Int, t: Int, r: Int, b: Int) {
viewBinding.shadowLayout.setPadding(l, t, r, b)
}
fun setCornerRadius(radius: Int) {
viewBinding.shadowLayout.setCornerRadius(radius)
}
fun setLayoutBackgroundColor(color: Int) {
viewBinding.shadowLayout.setLayoutBackground(color)
}
fun setLayoutBackgroundTrueColor(color: Int) {
viewBinding.shadowLayout.setLayoutBackgroundTrue(color)
}
override fun setOnClickListener(l: OnClickListener?) {
viewBinding.shadowLayout.setOnClickListener {
l?.onClick(it)
}
}
}
<widget.ShadowButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:shadow_button_background="#4DCB56"
app:shadow_button_text="联系老师"
app:shadow_button_textColor="@color/white" />
请对ShadowLayout本身提问题。你这是自己去重写。出了问题 我不可能从你重写的代码里去找问题。通过ShadowLayot本demo测试,不存在这样的问题。感谢你的支持
好吧 知道问题了 这应该是华为曲面屏边上做了防误触的原因 模拟器 直屏手机都没问题 感谢