1919
2020import android .annotation .TargetApi ;
2121import android .content .Context ;
22+ import android .content .res .Resources ;
2223import android .content .res .TypedArray ;
2324import android .graphics .drawable .Drawable ;
2425import android .os .Build ;
26+ import android .support .annotation .DrawableRes ;
27+ import android .support .annotation .NonNull ;
2528import android .text .TextUtils ;
2629import android .util .AttributeSet ;
2730import android .util .SparseBooleanArray ;
@@ -233,10 +236,10 @@ private void init(AttributeSet attrs) {
233236 mCollapseDrawable = typedArray .getDrawable (R .styleable .ExpandableTextView_collapseDrawable );
234237
235238 if (mExpandDrawable == null ) {
236- mExpandDrawable = getResources (). getDrawable ( R .drawable .ic_expand_small_holo_light , null );
239+ mExpandDrawable = getDrawable ( getResources (), R .drawable .ic_expand_small_holo_light );
237240 }
238241 if (mCollapseDrawable == null ) {
239- mCollapseDrawable = getResources (). getDrawable ( R .drawable .ic_collapse_small_holo_light , null );
242+ mCollapseDrawable = getDrawable ( getResources (), R .drawable .ic_collapse_small_holo_light );
240243 }
241244
242245 typedArray .recycle ();
@@ -254,6 +257,10 @@ private static boolean isPostHoneycomb() {
254257 return Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ;
255258 }
256259
260+ private static boolean isPostLolipop () {
261+ return Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ;
262+ }
263+
257264 @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
258265 private static void applyAlphaAnimation (View view , float alpha ) {
259266 if (isPostHoneycomb ()) {
@@ -267,7 +274,16 @@ private static void applyAlphaAnimation(View view, float alpha) {
267274 }
268275 }
269276
270- private static int getRealTextViewHeight (TextView textView ) {
277+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
278+ private static Drawable getDrawable (@ NonNull Resources resources , @ DrawableRes int resId ) {
279+ if (isPostLolipop ()) {
280+ return resources .getDrawable (resId , null );
281+ } else {
282+ return resources .getDrawable (resId );
283+ }
284+ }
285+
286+ private static int getRealTextViewHeight (@ NonNull TextView textView ) {
271287 int textHeight = textView .getLayout ().getLineTop (textView .getLineCount ());
272288 int padding = textView .getCompoundPaddingTop () + textView .getCompoundPaddingBottom ();
273289 return textHeight + padding ;
0 commit comments