Facing a very strange issue and not able to find any solution here or any other blogs.
Initially, a view is invisible and using AlphaAnimation and ScaleAnimation making it visible.
Animation Code
public void scaleView(View v, int delay) {
AnimationSet animatorSet = new AnimationSet(true);
animatorSet.setFillAfter(true);
animatorSet.setInterpolator(new LinearOutSlowInInterpolator());
AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(200);
animation1.setStartOffset(delay);
ScaleAnimation fadeIn = new ScaleAnimation(0.5f, 1f, 0.5f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
fadeIn.setDuration(200);
fadeIn.setStartOffset(delay);
animatorSet.addAnimation(animation1);
animatorSet.addAnimation(fadeIn);
animatorSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
v.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
v.startAnimation(animatorSet);
}
View
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llContainerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/app_bg_f8"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rlFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_20"
android:layout_marginEnd="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_10"
android:contentDescription="@string/lbl_login_with_facebook"
android:importantForAccessibility="yes"
android:visibility="invisible">
<LinearLayout
android:id="@+id/llLoginWithFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_facebook_login_32"
android:minHeight="@dimen/dp_48">
<ImageView
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/dp_16"
android:scaleType="center"
android:src="@drawable/ic_facebook_logo" />
<View
style="@style/ShadowVertical"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_10" />
<TextView
android:id="@+id/txtFacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/dp_10"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/lbl_login_with_facebook"
android:textColor="@color/white"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<ImageView
android:id="@+id/imgLoginWithFacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/llLoginWithFacebook"
android:layout_alignTop="@+id/llLoginWithFacebook"
android:layout_alignEnd="@id/llLoginWithFacebook"
android:layout_alignBottom="@id/llLoginWithFacebook"
android:background="@drawable/bg_ripple_32" />
</RelativeLayout>
</RelativeLayout>
My efforts on making it accessible
1) Added Content Description:
android:contentDescription="@string/lbl_login_with_facebook"
2) Adding a content description in view is enough but still, it was not working so after animation add I add focus and told the compiler that it is important by the following snippet:
v.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
But still, no luck to get focus. Can anyone help me to figure out how to make it accessible?
I think you have a simple mistake in your code. Try changing this:
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
to this
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.