Browse Source

@fun: select background

bai 2 years ago
parent
commit
cd3b5f17ca

+ 15 - 14
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/SelectButton.kt

@@ -21,6 +21,7 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import com.ys.bdtp.adm.R
 import com.ys.bdtp.adm.app.theme.textBlackColor
+import com.ys.bdtp.adm.app.theme.textBlueColor
 import com.ys.bdtp.adm.app.theme.whiteColor
 
 private val contentPadding = PaddingValues()
@@ -44,15 +45,15 @@ sealed interface SelectState {
 }
 
 @Composable
-fun SelectButton(initState: SelectState, click: (SelectState) -> Unit) {
+fun SelectButton(initState: SelectState, select: (SelectState) -> Unit) {
     var state by remember { mutableStateOf(initState) }
-    var leftResId by remember { mutableStateOf(R.drawable.btn_bg_blue_left_close) }
-    var rightResId by remember { mutableStateOf(R.drawable.btn_bg_gray_right_open) }
+    var leftResId by remember { mutableStateOf(R.drawable.select_left_blue_bg) }
+    var rightResId by remember { mutableStateOf(R.drawable.select_right_gray_bg) }
 
     Row(
         modifier = Modifier
-            .width(360.dp)
-            .height(32.dp)
+            .width(320.dp)
+            .height(36.dp)
             .background(Color.White, shape = RoundedCornerShape(4.dp))
     ) {
         TextButton(
@@ -60,16 +61,16 @@ fun SelectButton(initState: SelectState, click: (SelectState) -> Unit) {
             onClick = {
                 if (state != SelectState.Left) {
                     state = SelectState.Left
-                    leftResId = R.drawable.btn_bg_blue_left_close
-                    rightResId = R.drawable.btn_bg_gray_right_open
-                    click(state)
+                    leftResId = R.drawable.select_left_blue_bg
+                    rightResId = R.drawable.select_right_gray_bg
+                    select(state)
                 }
             },
             contentPadding = contentPadding,
             shape = leftShape,
             colors = ButtonDefaults.textButtonColors(
                 backgroundColor = whiteColor,
-                contentColor = textBlackColor
+                contentColor = if (state == SelectState.Left) textBlueColor else textBlackColor
             )
         ) {
             Box {
@@ -91,16 +92,16 @@ fun SelectButton(initState: SelectState, click: (SelectState) -> Unit) {
             onClick = {
                 if (state != SelectState.Right) {
                     state = SelectState.Right
-                    leftResId = R.drawable.btn_bg_gray_left_open
-                    rightResId = R.drawable.btn_bg_blue_right_close
-                    click(state)
+                    leftResId = R.drawable.select_left_gray_bg
+                    rightResId = R.drawable.select_right_blue_bg
+                    select(state)
                 }
             },
             contentPadding = contentPadding,
             shape = rightShape,
             colors = ButtonDefaults.textButtonColors(
                 backgroundColor = whiteColor,
-                contentColor = textBlackColor
+                contentColor = if (state == SelectState.Right) textBlueColor else textBlackColor
             )
         ) {
             Box {
@@ -122,5 +123,5 @@ fun SelectButton(initState: SelectState, click: (SelectState) -> Unit) {
 @Preview
 @Composable
 fun PreviewSelectButton() {
-    SelectButton(SelectState.Left, click = { state -> })
+    SelectButton(SelectState.Left, select = { state -> })
 }

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadScreen.kt

@@ -48,7 +48,7 @@ fun CadScreen(projectId: String) {
 
             SelectButton(
                 SelectState.Left,
-                click = {
+                select = {
                     selectState = it
                 }
             )

BIN
app/src/main/res/drawable-hdpi/select_left_gray_bg.png


BIN
app/src/main/res/drawable-hdpi/select_right_gray_bg.png


BIN
app/src/main/res/drawable-xhdpi/select_left_gray_bg.png


BIN
app/src/main/res/drawable-xhdpi/select_right_gray_bg.png