@@ -81,22 +81,63 @@ public void onClick(View view) {
81
81
} else {
82
82
//如果只是要显示在屏幕的下方
83
83
//decorView是activity的根View,包含 contentView 和 titleView
84
+ // if (mPickerOptions.decorView == null) {
85
+ // if (context instanceof Activity) {
86
+ // mPickerOptions.decorView = (ViewGroup) ((Activity) context).getWindow().getDecorView();
87
+ //
88
+ // ((Activity) context).getWindow().
89
+ // } else if (context instanceof ContextThemeWrapper && ((ContextThemeWrapper) context).getBaseContext() instanceof Activity) {
90
+ // mPickerOptions.decorView = (ViewGroup) ((Activity) ((ContextThemeWrapper) context).getBaseContext()).getWindow().getDecorView();
91
+ // }
92
+ // }
93
+ // //将控件添加到decorView中
94
+ // rootView = (ViewGroup) layoutInflater.inflate(R.layout.layout_basepickerview, mPickerOptions.decorView, false);
95
+ // rootView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
96
+ // if (mPickerOptions.outSideColor != -1) {
97
+ // rootView.setBackgroundColor(mPickerOptions.outSideColor);
98
+ // }
99
+ // //这个是真正要加载时间选取器的父布局
100
+ // contentContainer = (ViewGroup) rootView.findViewById(R.id.content_container);
101
+ // contentContainer.setLayoutParams(params);
102
+
84
103
if (mPickerOptions .decorView == null ) {
85
104
if (context instanceof Activity ) {
105
+ // Get the decor view of the current activity and use it as the decorView for your picker
86
106
mPickerOptions .decorView = (ViewGroup ) ((Activity ) context ).getWindow ().getDecorView ();
107
+
108
+ // Add your rootView to the decor view of the activity
109
+ rootView = (ViewGroup ) layoutInflater .inflate (R .layout .layout_basepickerview , mPickerOptions .decorView , false );
110
+ rootView .setLayoutParams (new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
111
+ if (mPickerOptions .outSideColor != -1 ) {
112
+ rootView .setBackgroundColor (mPickerOptions .outSideColor );
113
+ }
114
+
115
+ // Find the content container within your rootView
116
+ contentContainer = (ViewGroup ) rootView .findViewById (R .id .content_container );
117
+ contentContainer .setLayoutParams (params );
118
+
119
+ // Add the rootView to the decor view of the activity
120
+ ((ViewGroup ) ((Activity ) context ).getWindow ().getDecorView ()).addView (rootView );
87
121
} else if (context instanceof ContextThemeWrapper && ((ContextThemeWrapper ) context ).getBaseContext () instanceof Activity ) {
122
+ // If the context is a ContextThemeWrapper, get the base context which should be the activity
88
123
mPickerOptions .decorView = (ViewGroup ) ((Activity ) ((ContextThemeWrapper ) context ).getBaseContext ()).getWindow ().getDecorView ();
124
+
125
+ // Add your rootView to the decor view of the activity
126
+ rootView = (ViewGroup ) layoutInflater .inflate (R .layout .layout_basepickerview , mPickerOptions .decorView , false );
127
+ rootView .setLayoutParams (new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
128
+ if (mPickerOptions .outSideColor != -1 ) {
129
+ rootView .setBackgroundColor (mPickerOptions .outSideColor );
130
+ }
131
+
132
+ // Find the content container within your rootView
133
+ contentContainer = (ViewGroup ) rootView .findViewById (R .id .content_container );
134
+ contentContainer .setLayoutParams (params );
135
+
136
+ // Add the rootView to the decor view of the activity
137
+ ((ViewGroup ) ((Activity ) context ).getWindow ().getDecorView ()).addView (rootView );
89
138
}
90
139
}
91
- //将控件添加到decorView中
92
- rootView = (ViewGroup ) layoutInflater .inflate (R .layout .layout_basepickerview , mPickerOptions .decorView , false );
93
- rootView .setLayoutParams (new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
94
- if (mPickerOptions .outSideColor != -1 ) {
95
- rootView .setBackgroundColor (mPickerOptions .outSideColor );
96
- }
97
- //这个是真正要加载时间选取器的父布局
98
- contentContainer = (ViewGroup ) rootView .findViewById (R .id .content_container );
99
- contentContainer .setLayoutParams (params );
140
+
100
141
}
101
142
setKeyBackCancelable (true );
102
143
}
0 commit comments