use*_*496 5 android accessibility selection textfield android-jetpack-compose
我正在使用 TalkBack 测试我的应用程序的辅助功能兼容性。但是,某些 OutlinedTextFields 会被跳过,并且即使通过单击(如果启用了 TalkBack)也无法选择。我使用最新版本的 Kotlin/Gradle/Compose 创建了一个示例应用程序,以确保它与我的项目设置无关。
将“占位符”文本更改为某些值允许 TalkBack 选择,而其他值则使其不可选择(例如“MM/DD/YYYY”使 TalkBack 跳过该字段,但“Hello World”允许 TalkBack 选择该字段)。
代码如下:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PlaygroundTheme {
// A surface container using the 'background' color from the theme
Column(
modifier = Modifier.fillMaxSize(),
) {
Greeting("Android")
OutlinedTextField(
value = remember{mutableStateOf("")}.value,
onValueChange = {
},
label = {
Text(text = "Date of Birth")
},
placeholder = {
Text(text = "MM/DD/YYYY") //TalkBack won't select the field with this placeholder
// Text(text = "Hello World") //TalkBack WILL select the field with this placeholder
}
)
}
}
}
}
}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
Run Code Online (Sandbox Code Playgroud)
以下是我正在使用的依赖项:
buildscript {
ext {
compose_version = '1.3.0-alpha01'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
Run Code Online (Sandbox Code Playgroud)
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.playground"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha14'
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0'
implementation 'androidx.activity:activity-compose:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
Run Code Online (Sandbox Code Playgroud)
TalkBack 是否禁止某些字符串或字符?
我有同样的问题...我运行了一些测试(使用 androidx.compose.ui:ui:1.3.0-beta03):
\n当我们放置 a和 a时,行为有所TextField不同。Google 的问题跟踪器上也有一些类似的问题,请参见此处、此处或此处。OutlinedTextFieldplaceholderlabel
label除了仅使用an之外,我没有找到其他解决方案OutlinedTextField,因为可访问性对我们来说不是可选的。我用我制作的以下示例在Google 的跟踪器上提出了一个新问题,结果:
Column(\n modifier = Modifier\n .fillMaxSize()\n .padding(all = 16.dp)\n .verticalScroll(state = rememberScrollState()),\n) {\n // OutlinedTextField empty.\xe2\x9d\x8c\n Text(text = "OutlinedTextField empty")\n Spacer(modifier = Modifier.height(height = 4.dp))\n OutlinedTextField(\n value = "",\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // OutlinedTextField with placeholder.\xe2\x9c\x85\n Text(text = "OutlinedTextField with placeholder")\n Spacer(modifier = Modifier.height(height = 4.dp))\n OutlinedTextField(\n value = "",\n placeholder = { Text(text = "Placeholder") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // OutlinedTextField with placeholder and label.\xe2\x9d\x8c\n Text(text = "OutlinedTextField with placeholder and label")\n OutlinedTextField(\n value = "",\n placeholder = { Text(text = "Placeholder") },\n label = { Text(text = "Label") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // OutlinedTextField with label.\xe2\x9c\x85\n Text(text = "OutlinedTextField with label")\n OutlinedTextField(\n value = "",\n label = { Text(text = "Label") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // TextField empty.\xe2\x9d\x8c\n Text(text = "TextField empty")\n Spacer(modifier = Modifier.height(height = 4.dp))\n TextField(\n value = "",\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // TextField with placeholder.\xe2\x9c\x85\n Text(text = "TextField with Placeholder")\n Spacer(modifier = Modifier.height(height = 4.dp))\n TextField(\n value = "",\n placeholder = { Text(text = "Placeholder") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n\n // TextField with placeholder and label.\xe2\x9c\x85\n Text(text = "TextField with Placeholder and label")\n Spacer(modifier = Modifier.height(height = 4.dp))\n TextField(\n value = "",\n placeholder = { Text(text = "Placeholder") },\n label = { Text(text = "Label") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n\n // TextField with label.\xe2\x9c\x85\n Text(text = "TextField with label")\n Spacer(modifier = Modifier.height(height = 4.dp))\n TextField(\n value = "",\n label = { Text(text = "Label") },\n onValueChange = { },\n modifier = Modifier.fillMaxWidth(),\n )\n Spacer(modifier = Modifier.height(height = 12.dp))\n}\nRun Code Online (Sandbox Code Playgroud)\n\n
| 归档时间: |
|
| 查看次数: |
2069 次 |
| 最近记录: |