Ami*_*ein 5 android-jetpack-compose android-jetpack-compose-text
我正在寻找 jetpack compose 中的阿拉伯符号支持。我想更改一些阿拉伯标点符号的颜色并自定义它们的外观。目前,我正在使用此功能来实现此目的:
\nprivate fun colorPonctuation(input: String): AnnotatedString {\n return buildAnnotatedString {\n input.forEach {\n if (it == \'\\u064B\' || it == \'\\u064D\'\n || it == \'\\u064D\' || it == \'\\u064E\' || it == \'\\u064F\' ||\n it == \'\\u0650\' || it == \'\\u0651\' || it == \'\\u0652\' || it == \'\\u0653\' ||\n it == \'\\u0654\' || it == \'\\u0655\' || it == \'\\u0656\' || it == \'\\u0657\' ||\n it == \'\\u0658\' || it == \'\\u0659\' || it == \'\\u065A\' || it == \'\\u065B\' ||\n it == \'\\u065C\' || it == \'\\u065D\' || it == \'\\u065E\' || it == \'\\u065F\' || it == \'\\u0670\'\n ) {\n withStyle(style = SpanStyle(color = Color.Red)) {\n append(it)\n }\n } else {\n withStyle(style = SpanStyle(color = Color.Blue)) {\n append(it)\n }\n }\n }\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n使用它,阿拉伯符号和标点符号会改变它们的颜色,但也会改变它们在最终字符串中的位置,这不是我想要的。
\n这是我正在使用的完整代码:
\nclass Arabic : ComponentActivity() {\noverride fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContent {\n MaterialTheme {\n PreviewArabicText()\n }\n }\n}\n\n\n@Composable\nfun ShowArabicText() {\n val str by remember { mutableStateOf(AnnotatedString("\xd8\xa8\xd9\x90\xd8\xb3\xd9\x92\xd9\x85\xd9\x90 \xd8\xa7\xd9\x84\xd9\x84\xd9\x87\xd9\x90 \xd8\xa7\xd9\x84\xd8\xb1\xd9\x91\xd8\xad\xd9\x92\xd9\x85\xd9\x86\xd9\x90 \xd8\xa7\xd9\x84\xd8\xb1\xd9\x8e\xd9\x91\xd8\xad\xd9\x90\xdb\x8c\xd9\x85")) }\n val text by remember { mutableStateOf("\xd8\xa8\xd9\x90\xd8\xb3\xd9\x92\xd9\x85\xd9\x90 \xd8\xa7\xd9\x84\xd9\x84\xd9\x87\xd9\x90 \xd8\xa7\xd9\x84\xd8\xb1\xd9\x91\xd8\xad\xd9\x92\xd9\x85\xd9\x86\xd9\x90 \xd8\xa7\xd9\x84\xd8\xb1\xd9\x8e\xd9\x91\xd8\xad\xd9\x90\xdb\x8c\xd9\x85") }\n var isSelected by remember { mutableStateOf(false) }\n Column(\n modifier = Modifier.fillMaxSize(),\n verticalArrangement = Arrangement.Center,\n horizontalAlignment = Alignment.CenterHorizontally\n ) {\n\n Text(\n text = if (isSelected) colorPonctuation(text) else str,\n color = Color.Blue,\n fontWeight = FontWeight.Bold,\n fontFamily = FontFamily.Default,\n fontStyle = FontStyle.Normal,\n fontSize = 30.sp\n )\n\n Spacer(modifier = Modifier.width(10.dp))\n\n Button(onClick = {\n isSelected = !isSelected\n }) {\n Text(text = "change color")\n }\n }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n在这里您可以看到阿拉伯符号的不需要的位置变化:
\n\n 归档时间: |
|
查看次数: |
514 次 |
最近记录: |