1
1
package com .chinalwb .are .styles .toolbar ;
2
2
3
- import android .app .Activity ;
4
3
import android .content .Context ;
5
4
import android .content .Intent ;
5
+ import android .content .res .TypedArray ;
6
6
import android .util .AttributeSet ;
7
7
import android .view .Gravity ;
8
8
import android .view .View ;
9
9
import android .widget .HorizontalScrollView ;
10
10
import android .widget .LinearLayout ;
11
11
12
12
import com .chinalwb .are .AREditText ;
13
+ import com .chinalwb .are .R ;
13
14
import com .chinalwb .are .Util ;
14
15
import com .chinalwb .are .styles .toolitems .IARE_ToolItem ;
15
16
16
17
import java .util .ArrayList ;
17
18
import java .util .List ;
18
19
20
+ import androidx .annotation .DrawableRes ;
21
+
19
22
/**
20
23
* Created by wliu on 13/08/2018.
21
24
*/
@@ -29,6 +32,10 @@ public class ARE_ToolbarDefault extends HorizontalScrollView implements IARE_Too
29
32
30
33
private AREditText mAREditText ;
31
34
35
+ @ DrawableRes
36
+ private int mIconBackground ;
37
+ private int mIconSize ;
38
+
32
39
public ARE_ToolbarDefault (Context context ) {
33
40
this (context , null );
34
41
}
@@ -39,13 +46,13 @@ public ARE_ToolbarDefault(Context context, AttributeSet attrs) {
39
46
40
47
public ARE_ToolbarDefault (Context context , AttributeSet attrs , int defStyle ) {
41
48
super (context , attrs , defStyle );
42
- this .mContext = ( Activity ) context ;
43
- initSelf ();
49
+ this .mContext = context ;
50
+ initSelf (context , attrs );
44
51
}
45
52
46
53
@ Override
47
54
public void addToolbarItem (IARE_ToolItem toolbarItem ) {
48
- toolbarItem .setToolbar (this );
55
+ toolbarItem .setToolbar (this , mIconBackground , mIconSize );
49
56
mToolItems .add (toolbarItem );
50
57
View view = toolbarItem .getView (mContext );
51
58
if (view != null ) {
@@ -75,11 +82,17 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
75
82
}
76
83
}
77
84
78
- private void initSelf () {
85
+ private void initSelf (Context context , AttributeSet attrs ) {
79
86
mContainer = new LinearLayout (mContext );
80
87
LayoutParams params = new LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .MATCH_PARENT );
81
88
mContainer .setGravity (Gravity .CENTER_VERTICAL );
82
89
mContainer .setLayoutParams (params );
83
90
this .addView (mContainer );
91
+
92
+ TypedArray ta = context .obtainStyledAttributes (attrs , R .styleable .ARE_ToolbarDefault );
93
+ mIconBackground = ta .getResourceId (R .styleable .ARE_ToolbarDefault_toolbarIconBackground , R .drawable .background_icon );
94
+ mIconSize = ta .getDimensionPixelSize (R .styleable .ARE_ToolbarDefault_toolbarIconSize , Util .getPixelByDp (context , 40 ));
95
+
96
+ ta .recycle ();
84
97
}
85
98
}
0 commit comments