张钢
2024-09-02 63608b5dca9eebb6fa2cb1a8652b395f1d910c3e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.application.zhangshi_app_android.other;
 
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
 
import androidx.appcompat.content.res.AppCompatResources;
 
import com.application.zhangshi_app_android.R;
import com.hjq.bar.style.CommonBarStyle;
 
/**
 * @author Ljj
 * @date 2023.03.30. 20:11
 * @desc TitleBar统一样式
 */
public class MyTitleBarStyle extends CommonBarStyle {
 
    @Override
    public Typeface getTitleTypeface(Context context, int style) {
        return Typeface.createFromAsset(context.getAssets(), "roboto_regular.ttf");
    }
 
    @Override
    public Typeface getLeftTitleTypeface(Context context, int style) {
        return Typeface.createFromAsset(context.getAssets(), "roboto_regular.ttf");
    }
 
    @Override
    public Typeface getRightTitleTypeface(Context context, int style) {
        return Typeface.createFromAsset(context.getAssets(), "roboto_regular.ttf");
    }
 
    @Override
    public Drawable getTitleBarBackground(Context context) {
        //根据当前主题获取不同的背景颜色
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.titleBarBackgroundColor, typedValue, true);
        return new ColorDrawable(typedValue.data);
    }
 
    @Override
    public Drawable getLeftTitleBackground(Context context) {
        return null;
    }
 
    @Override
    public Drawable getRightTitleBackground(Context context) {
        return null;
    }
 
    @Override
    public Drawable getBackButtonDrawable(Context context) {
        return AppCompatResources.getDrawable(context,R.drawable.ic_menu);
    }
 
    @Override
    public ColorStateList getTitleColor(Context context) {
        return ColorStateList.valueOf(0xFFFFFFFF);
    }
 
    @Override
    public ColorStateList getLeftTitleColor(Context context) {
        return null;
    }
 
    @Override
    public ColorStateList getRightTitleColor(Context context) {
        return null;
    }
 
    @Override
    public Drawable getLineDrawable(Context context) {
        return null;
    }
 
    @Override
    public int getLeftHorizontalPadding(Context context) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources().getDisplayMetrics());
    }
 
    @Override
    public float getTitleSize(Context context) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, context.getResources().getDisplayMetrics());
    }
 
    @Override
    public int getLeftIconPadding(Context context) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources().getDisplayMetrics());
    }
 
 
 
}