下面列出了android.support.v4.view.ViewCompat#setAccessibilityLiveRegion ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Floaty(ViewGroup parent, View content) {
if (parent == null) {
throw new IllegalArgumentException("Transient bottom bar must have non-null parent");
}
if (content == null) {
throw new IllegalArgumentException("Transient bottom bar must have non-null content");
}
targetParent = parent;
context = parent.getContext();
view = (FloatyContentLayout) content;
stage = Stage.of(targetParent);
ViewCompat.setAccessibilityLiveRegion(stage, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
ViewCompat.setImportantForAccessibility(stage, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
// Make sure that we fit system windows and have a listener to apply any insets
stage.setFitsSystemWindows(true);
ViewCompat.setOnApplyWindowInsetsListener(stage,
new android.support.v4.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
// Copy over the bottom inset as padding so that we're displayed
// above the navigation bar
v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(),
insets.getSystemWindowInsetBottom());
return insets;
}
});
accessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
scene = new Scene(stage, view);
}
public SnackbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
mMaxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1);
mMaxInlineActionWidth = a.getDimensionPixelSize(
R.styleable.SnackbarLayout_maxActionInlineWidth, -1);
if (a.hasValue(R.styleable.SnackbarLayout_elevation)) {
ViewCompat.setElevation(this, a.getDimensionPixelSize(
R.styleable.SnackbarLayout_elevation, 0));
}
a.recycle();
setClickable(true);
// Now inflate our content. We need to do this manually rather than using an <include>
// in the layout since older versions of the Android do not inflate includes with
// the correct Context.
LayoutInflater.from(context).inflate(com.jet.sweettips.R.layout.sweet_layout_snackbar_include, this);
ViewCompat.setAccessibilityLiveRegion(this,
ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
ViewCompat.setImportantForAccessibility(this,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
// Make sure that we fit system windows and have a listener to apply any insets
ViewCompat.setFitsSystemWindows(this, true);
ViewCompat.setOnApplyWindowInsetsListener(this,
new android.support.v4.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
// Copy over the bottom inset as padding so that we're displayed above the
// navigation bar
v.setPadding(v.getPaddingLeft(), v.getPaddingTop(),
v.getPaddingRight(), insets.getSystemWindowInsetBottom());
return insets;
}
});
}
/**
* Creates a toolbar progress bar.
*
* @param context the application environment.
* @param attrs the xml attributes that should be used to initialize this view.
*/
public ToolbarProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
setAlpha(0.0f);
// This tells accessibility services that progress bar changes are important enough to
// announce to the user even when not focused.
ViewCompat.setAccessibilityLiveRegion(this, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
}
/**
* Creates a toolbar progress bar.
*
* @param context the application environment.
* @param attrs the xml attributes that should be used to initialize this view.
*/
public ToolbarProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
setAlpha(0.0f);
// This tells accessibility services that progress bar changes are important enough to
// announce to the user even when not focused.
ViewCompat.setAccessibilityLiveRegion(this, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
}
public SnackbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
mMaxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1);
mMaxInlineActionWidth = a.getDimensionPixelSize(
R.styleable.SnackbarLayout_maxActionInlineWidth, -1);
if (a.hasValue(R.styleable.SnackbarLayout_elevation)) {
ViewCompat.setElevation(this, a.getDimensionPixelSize(
R.styleable.SnackbarLayout_elevation, 0));
}
a.recycle();
setClickable(true);
// Now inflate our content. We need to do this manually rather than using an <include>
// in the layout since older versions of the Android do not inflate includes with
// the correct Context.
LayoutInflater.from(context).inflate(com.jet.sweettips.R.layout.sweet_layout_snackbar_include, this);
ViewCompat.setAccessibilityLiveRegion(this,
ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
ViewCompat.setImportantForAccessibility(this,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
// Make sure that we fit system windows and have a listener to apply any insets
ViewCompat.setFitsSystemWindows(this, true);
ViewCompat.setOnApplyWindowInsetsListener(this,
new android.support.v4.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
// Copy over the bottom inset as padding so that we're displayed above the
// navigation bar
v.setPadding(v.getPaddingLeft(), v.getPaddingTop(),
v.getPaddingRight(), insets.getSystemWindowInsetBottom());
return insets;
}
});
}
/**
* Creates a toolbar progress bar.
*
* @param context The application environment.
* @param height The height of the progress bar in px.
* @param topMargin The top margin of the progress bar.
* @param useStatusBarColorAsBackground Whether or not to use the status bar color as the
* background of the toolbar.
*/
public ToolbarProgressBar(
Context context, int height, int topMargin, boolean useStatusBarColorAsBackground) {
super(context, height);
setAlpha(0.0f);
mMarginTop = topMargin;
mUseStatusBarColorAsBackground = useStatusBarColorAsBackground;
// This tells accessibility services that progress bar changes are important enough to
// announce to the user even when not focused.
ViewCompat.setAccessibilityLiveRegion(this, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
}