docs: 修正计划示例中的硬编码文案(R9),补齐 stringResource 用法与警示
This commit is contained in:
@@ -385,6 +385,7 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
||||
/** 唯一 Activity,承载 Compose 界面。 */
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -395,7 +396,7 @@ class MainActivity : ComponentActivity() {
|
||||
MaterialTheme {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Text("RingHealth")
|
||||
Text(stringResource(R.string.app_name))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -631,14 +632,19 @@ setContent {
|
||||
RingHealthTheme {
|
||||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Text("RingHealth")
|
||||
Text(stringResource(R.string.app_name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
并补充 import:`com.placeholder.ringhealth.core.designsystem.RingHealthTheme`。
|
||||
并补充 import:`com.placeholder.ringhealth.core.designsystem.RingHealthTheme`、
|
||||
`androidx.compose.ui.res.stringResource`。
|
||||
|
||||
注意:文案必须走 `stringResource(R.string.app_name)`,不得写成 `Text("RingHealth")` 字面量 ——
|
||||
全局约束「不硬编码用户可见文案」对 Compose 里的每一处 `Text(...)` 都成立。Task 1 的初版
|
||||
就是因为计划里的示例代码写成了字面量而引入该缺陷,修复轮才扳正(见 ledger 裁定)。
|
||||
|
||||
- [ ] **Step 5: 构建验证**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user