14 | * 这些Attribute是具体View的对应Styleable中的值 15 | * 这些值不但是作为MultiTheme中用来索引的Key,也是通过其从XML解析出的Attribute中取出主题元素的值的关键。 16 | *
17 | * 例: 18 | * android:background="?attr/theme_background" 19 | *
20 | * View中都有'android.R.attr.background'的标签,添加其作为View的MultiThemeAttrs,那么MultiTheme 21 | * 就会将'background'标签下的'theme_background'对应attrRes取出,作为主题元素的值来存储。当主题改变 22 | * 的时候,通过'android.R.attr.background'找到attrRes,然后分发到对应的 23 | * {@link io.github.leonhover.theme.widget.ViewWidget}的'applyElementTheme'。 24 | *
25 | * Created by wangzongliang on 2017/2/14.
26 | */
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Target(ElementType.TYPE)
29 | @Inherited
30 | public @interface MultiThemeAttrs {
31 | @AttrRes int[] value();
32 | }
33 |
--------------------------------------------------------------------------------
/AndroidMultiTheme/android-multi-theme/src/main/java/io/github/leonhover/theme/widget/SeekBarWidget.java:
--------------------------------------------------------------------------------
1 | package io.github.leonhover.theme.widget;
2 |
3 | import androidx.annotation.AnyRes;
4 | import androidx.annotation.AttrRes;
5 | import androidx.annotation.DrawableRes;
6 | import android.view.View;
7 | import android.widget.AbsSeekBar;
8 |
9 | import io.github.leonhover.theme.annotation.MultiThemeAttrs;
10 |
11 | /**
12 | * Created by leonhover on 16-9-27.
13 | */
14 | @MultiThemeAttrs({
15 | android.R.attr.thumb
16 | })
17 | public class SeekBarWidget extends ProgressBarWidget {
18 | @Override
19 | public void applyElementTheme(View view, @AttrRes int themeElementKey, @AnyRes int resId) {
20 | super.applyElementTheme(view, themeElementKey, resId);
21 | AbsSeekBar seekBar = (AbsSeekBar) view;
22 | switch (themeElementKey) {
23 | case android.R.attr.thumb:
24 | setThumb(seekBar, resId);
25 | break;
26 | }
27 | }
28 |
29 | public static void setThumb(AbsSeekBar seekBar, @DrawableRes int drawableResId) {
30 | if (seekBar == null) {
31 | return;
32 | }
33 |
34 | seekBar.setThumb(getDrawable(seekBar, drawableResId));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AndroidMultiTheme/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |