Add content description to the master switch toggle button.
Set the preference title as the toggle button's content description, so that when user focus on the button, it will read the lable as well on top of just "switch on" or "switch off". Change-Id: Id1954fd54b7d38cb4e75d8b3e49d05ee694e0e41 Fix: 37618855 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -83,6 +83,7 @@ public class MasterSwitchPreference extends TwoTargetPreference {
|
||||
|
||||
mSwitch = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setContentDescription(getTitle());
|
||||
mSwitch.setChecked(mChecked);
|
||||
mSwitch.setEnabled(mEnableSwitch);
|
||||
}
|
||||
|
@@ -183,4 +183,19 @@ public class MasterSwitchPreferenceTest {
|
||||
preference.setDisabledByAdmin(null);
|
||||
assertThat(toggle.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_toggleButtonShouldHaveContentDescription() {
|
||||
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.preference_widget_master_switch, null));
|
||||
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
final String label = "TestButton";
|
||||
preference.setTitle(label);
|
||||
|
||||
preference.onBindViewHolder(holder);
|
||||
|
||||
assertThat(toggle.getContentDescription()).isEqualTo(label);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user