下面列出了怎么用android.support.v7.widget.TintContextWrapper的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 判断Activity是否已经结束
*
* @return true:已结束
*/
boolean activityIsAlive() {
TextView textView = textViewWeakReference.get();
if (textView == null) {
return false;
}
Context context = textView.getContext();
if (context == null) {
return false;
}
if (context instanceof TintContextWrapper) {
context = ((TintContextWrapper) context).getBaseContext();
}
if (context instanceof Activity) {
if (((Activity) context).isFinishing()) {
return false;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && ((Activity) context).isDestroyed()) {
return false;
}
}
}
return true;
}
final View createView(View parent, final String name, @NonNull Context context,
@NonNull AttributeSet attrs, boolean inheritContext,
boolean readAppTheme, boolean wrapContext) {
if (inheritContext && parent != null) {
context = parent.getContext();
}
if (readAppTheme) {
context = themifyContext(context, attrs, true);
}
if (wrapContext) {
context = TintContextWrapper.wrap(context);
}
View view = createViewFromTag(context, name, attrs);
if (view != null) {
checkOnClickListener(view, attrs);
}
return view;
}
public final View createView(View parent, final String name, @NonNull Context context,
@NonNull AttributeSet attrs, boolean inheritContext,
boolean readAndroidTheme, boolean readAppTheme, boolean wrapContext) {
final Context originalContext = context;
// We can emulate Lollipop's android:theme attribute propagating down the view hierarchy
// by using the parent's context
if (inheritContext && parent != null) {
context = parent.getContext();
}
if (readAndroidTheme || readAppTheme) {
// We then apply the theme on the context, if specified
context = themifyContext(context, attrs, readAndroidTheme, readAppTheme);
}
if (wrapContext) {
context = TintContextWrapper.wrap(context);
}
View view = createViewFromHackInflater(context, name, attrs);
// We need to 'inject' our tint aware Views in place of the standard framework versions
if (view == null) {
view = createViewFromFV(context, name, attrs);
}
if (view == null) {
view = createViewFromV7(context, name, attrs);
}
if (view == null) {
view = createViewFromInflater(context, name, attrs);
}
if (view == null) {
view = createViewFromTag(context, name, attrs);
}
if (view != null) {
// If we have created a view, check it's android:onClick
checkOnClickListener(view, attrs);
}
return view;
}