Tweak SettingsSpinner UI

1. Arrow icon size from 24 to 18
2. Round corner radius from 20 to 28
3. Height from 32 to 36
4. Set accentColor background to default view.
5. Set translucent accentColor background to default dropdown view.
6. Set dropdown view vertical offset to measured height.

Bug: 181833196
Test: manual visual
Change-Id: Ia538fd1831602ff38ba873c7f0a34d1ad5e90e18
This commit is contained in:
Arc Wang
2021-03-04 11:59:30 +08:00
parent bff3cb288c
commit b175c283b0
9 changed files with 107 additions and 21 deletions

View File

@@ -16,11 +16,11 @@
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="24"
android:viewportHeight="24"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="24dp"
android:height="24dp">
<path
android:pathData="M7 10l5 5 5 -5z"
android:fillColor="?android:attr/textColorPrimary"/>
</vector>
android:fillColor="@android:color/black"/>
</vector>

View File

@@ -24,21 +24,21 @@
android:bottom="8dp">
<shape>
<corners
android:radius="20dp"/>
android:radius="28dp"/>
<solid
android:color="?android:attr/colorPrimary"/>
android:color="?android:attr/colorAccent"/>
<stroke
android:color="#1f000000"
android:color="?android:attr/colorPrimary"
android:width="1dp"/>
<size
android:height="32dp"/>
android:height="@dimen/spinner_height"/>
</shape>
</item>
<item
android:gravity="center|end"
android:width="24dp"
android:height="24dp"
android:end="4dp"
android:drawable="@drawable/arrow_drop_down_24dp"/>
android:width="18dp"
android:height="18dp"
android:end="8dp"
android:drawable="@drawable/arrow_drop_down"/>
</layer-list>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid
android:color="?android:attr/colorAccent"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#BBFFFFFF"/>
</shape>
</item>
</layer-list>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/SettingsSpinnerTitleBar"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/settings_spinner_dropdown_background"/>

View File

@@ -19,7 +19,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/SettingsSpinnerTitleBar"
android:maxLines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"/>
android:layout_height="wrap_content"/>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<dimen name="spinner_height">36dp</dimen>
<dimen name="spinner_padding_top_or_bottom">8dp</dimen>
</resources>

View File

@@ -18,9 +18,13 @@
<resources>
<style name="SettingsSpinnerTitleBar">
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:maxLines">1</item>
<item name="android:ellipsize">marquee</item>
<item name="android:minHeight">@dimen/spinner_height</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">36dp</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingTop">@dimen/spinner_padding_top_or_bottom</item>
<item name="android:paddingBottom">@dimen/spinner_padding_top_or_bottom</item>
</style>
</resources>
</resources>

View File

@@ -121,4 +121,11 @@ public class SettingsSpinner extends Spinner {
int mode) {
super(context, attrs, defStyleAttr, defStyleRes, mode, null);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setDropDownVerticalOffset(getMeasuredHeight() - (int) getContext().getResources()
.getDimension(R.dimen.spinner_padding_top_or_bottom));
}
}

View File

@@ -30,8 +30,7 @@ import com.android.settingslib.widget.R;
public class SettingsSpinnerAdapter<T> extends ArrayAdapter<T> {
private static final int DEFAULT_RESOURCE = R.layout.settings_spinner_view;
private static final int DFAULT_DROPDOWN_RESOURCE =
android.R.layout.simple_spinner_dropdown_item;
private static final int DFAULT_DROPDOWN_RESOURCE = R.layout.settings_spinner_dropdown_view;
private final LayoutInflater mDefaultInflater;
/**