Skip to content

Commit ca90045

Browse files
committed
[Focus Rings] Add support for common Framework and AppCompat component focus rings
PiperOrigin-RevId: 897050849
1 parent 59acbba commit ca90045

14 files changed

Lines changed: 762 additions & 4 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:color="?android:attr/colorControlHighlight">
20+
<item android:drawable="@drawable/m3_focus_ring_framework_button_background_shape" />
21+
22+
<item>
23+
<com.google.android.material.focus.FocusRingDrawable
24+
app:focusRingsRadius="2dp"
25+
app:focusRingsInset="2dp" />
26+
</item>
27+
</ripple>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:color="?android:attr/colorControlHighlight">
20+
<item android:id="@android:id/mask"
21+
android:drawable="@drawable/m3_focus_ring_framework_button_background_shape" />
22+
23+
<item>
24+
<com.google.android.material.focus.FocusRingDrawable
25+
app:focusRingsRadius="2dp"
26+
app:focusRingsInset="2dp" />
27+
</item>
28+
</ripple>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<inset xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:insetLeft="4dp"
19+
android:insetTop="6dp"
20+
android:insetRight="4dp"
21+
android:insetBottom="6dp">
22+
<shape android:shape="rectangle"
23+
android:tint="?android:attr/colorButtonNormal">
24+
<corners android:radius="2dp" />
25+
<solid android:color="@android:color/white" />
26+
<padding android:left="8dp"
27+
android:top="4dp"
28+
android:right="8dp"
29+
android:bottom="4dp" />
30+
</shape>
31+
</inset>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:color="?android:attr/colorControlHighlight">
20+
<item android:drawable="@drawable/m3_focus_ring_framework_button_background_shape" />
21+
22+
<item>
23+
<com.google.android.material.focus.FocusRingDrawable
24+
app:focusRingsRadius="?android:attr/buttonCornerRadius"
25+
app:focusRingsInset="2dp" />
26+
</item>
27+
</ripple>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<inset xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:insetLeft="4dp"
19+
android:insetTop="6dp"
20+
android:insetRight="4dp"
21+
android:insetBottom="6dp">
22+
<shape android:shape="rectangle"
23+
android:tint="?android:attr/colorButtonNormal">
24+
<corners android:radius="?android:attr/buttonCornerRadius" />
25+
<solid android:color="@android:color/white" />
26+
<padding android:left="8dp"
27+
android:top="4dp"
28+
android:right="8dp"
29+
android:bottom="4dp" />
30+
</shape>
31+
</inset>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2026 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<resources>
19+
20+
<!-- Styles for framework buttons with focus rings (on API 24+). -->
21+
<style name="Widget.Material.Button.FocusRing" parent="android:Widget.Material.Button">
22+
<item name="android:background">@drawable/m3_focus_ring_framework_button_background</item>
23+
</style>
24+
25+
<style name="Widget.Material.Button.Borderless.FocusRing" parent="android:Widget.Material.Button.Borderless">
26+
<item name="android:background">@drawable/m3_focus_ring_framework_button_background_borderless</item>
27+
</style>
28+
29+
<style name="Widget.Material.ImageButton.FocusRing" parent="android:Widget.Material.ImageButton">
30+
<item name="android:background">@drawable/m3_focus_ring_framework_button_background</item>
31+
</style>
32+
33+
</resources>

lib/java/com/google/android/material/button/res/values/styles.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,4 +1006,16 @@
10061006
<!-- Icon text button has the same padding as a regular text button -->
10071007
</style>
10081008

1009+
<!-- Styles for framework buttons with focus rings (on API 24+). -->
1010+
<style name="Widget.Material.Button.FocusRing" parent="android:Widget.Material.Button" />
1011+
1012+
<style name="Widget.Material.Button.Small.FocusRing" parent="Widget.Material.Button.FocusRing">
1013+
<item name="android:minHeight">48dip</item>
1014+
<item name="android:minWidth">48dip</item>
1015+
</style>
1016+
1017+
<style name="Widget.Material.Button.Borderless.FocusRing" parent="android:Widget.Material.Button.Borderless" />
1018+
1019+
<style name="Widget.Material.ImageButton.FocusRing" parent="android:Widget.Material.ImageButton" />
1020+
10091021
</resources>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2026 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<com.google.android.material.focus.FocusRingDrawable xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
app:focusRingsRadius="4dp"
20+
app:focusRingsInset="2dp">
21+
22+
<ripple
23+
android:color="@color/abc_color_highlight_material"
24+
android:radius="20dp"/>
25+
26+
</com.google.android.material.focus.FocusRingDrawable>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2026 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:color="@color/abc_color_highlight_material"
19+
android:radius="20dp"/>

lib/java/com/google/android/material/checkbox/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@
4545

4646
<style name="Widget.Material3.CompoundButton.CheckBox" parent="Base.Widget.Material3.CompoundButton.CheckBox" />
4747

48+
<style name="Widget.Material.CompoundButton.CheckBox.FocusRing" parent="android:Widget.Material.CompoundButton.CheckBox">
49+
<item name="android:background">@drawable/m3_focus_ring_framework_checkbox_background</item>
50+
</style>
51+
4852
</resources>

0 commit comments

Comments
 (0)