This commit is contained in:
zxj
2025-07-29 11:09:59 +08:00
parent df5acf6b61
commit 56e0a85a4c
106 changed files with 10986 additions and 92 deletions
@@ -0,0 +1,49 @@
package com.sw.dualscreen.ext
import android.content.res.Resources
import android.util.TypedValue
import androidx.annotation.Dimension
/**
* 将 Int 值转换为 dp 值
*/
val Int.dp: Int
@Dimension(unit = Dimension.DP)
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
).toInt()
/**
* 将 Float 值转换为 dp 值
*/
val Float.dp: Float
@Dimension(unit = Dimension.DP)
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
Resources.getSystem().displayMetrics
)
/**
* 将 Int 值转换为 sp 值
*/
val Int.sp: Float
@Dimension(unit = Dimension.SP)
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
this.toFloat(),
Resources.getSystem().displayMetrics
)
/**
* 将 Float 值转换为 sp 值
*/
val Float.sp: Float
@Dimension(unit = Dimension.SP)
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
this,
Resources.getSystem().displayMetrics
)
@@ -0,0 +1,30 @@
package com.sw.dualscreen.ext
import android.graphics.drawable.GradientDrawable
import android.view.View
import androidx.annotation.ColorInt
import androidx.core.graphics.toColorInt
/**
* 设置圆角边框
*/
fun View.setRoundedBorder(
@ColorInt solidColor: Int = "#19ECE7D0".toColorInt(), // 填充颜色
@ColorInt strokeColor: Int = "#ECE7D0".toColorInt(), // 边框颜色
strokeWidthDp: Float = 2f, // 边框宽度
cornerRadiusDp: Float = 24f, // 边框圆角
) {
background = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
setColor(solidColor)
setStroke(
dpToPx(strokeWidthDp).toInt(),
strokeColor
)
this.cornerRadius = dpToPx(cornerRadiusDp)
}
}
private fun View.dpToPx(dp: Float): Float {
return dp * context.resources.displayMetrics.density
}