In my application I have one text view and beside to that I need to show help icon. If text of the text view is 2 lines then help icons should show in second line and it should be at end of the text.
I am using below code:
MainActivity.java
public class WelcomeActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
final TextView tvTitle = findViewById(R.id.subtitle);
String sPageHeaderText = getResources().getString(R.string.welcomepage_message);
if (tvTitle != null) {
final Context context = this;
SpannableString spannable = new SpannableString(sPageHeaderText);
Drawable infoIcon = getResources().getDrawable(R.drawable.ic_info, null);
infoIcon.setBounds(0, 0, infoIcon.getIntrinsicWidth(), infoIcon.getIntrinsicHeight());
ImageSpan imgSpan = new ImageSpan(infoIcon, ImageSpan.ALIGN_BASELINE);
spannable.setSpan(imgSpan, sPageHeaderText.length() - 1, sPageHeaderText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
final SpannableString ss = spannable;
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
tvTitle.setText(ss);
//Shows help info dialog
}
@Override
public void updateDrawState(TextPaint tp) {
super.updateDrawState(tp);
tp.setUnderlineText(false);
tp.setColor(getResources().getColor(R.color.white, getTheme()));
}
};
spannable.setSpan(clickableSpan, sPageHeaderText.length() - 1, sPageHeaderText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tvTitle.setMovementMethod(LinkMovementMethod.getInstance());
tvTitle.setTransformationMethod(null);
tvTitle.setText(spannable);
tvTitle.setText(ss, TextView.BufferType.SPANNABLE);
}
}
}
welcome_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:orientation="vertical">
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_centerInParent="true"
android:focusable="true"
android:gravity="center_horizontal"
android:lineSpacingExtra="2dp"
android:text="@string/welcomepage_message"
android:textColor="#FFFFFF"
android:textSize="14sp" />
</RelativeLayout>
When user tap on help it shows the help dialog.
The issue here is when users make accessibility ON and select subtitle, it highlight both subtitle and help icon. Here users do not have options to select only help icon.
The requirement here is when accessibility ON users should be able to select the help icon independently and app should spell the content description provided for help icon.
Below is the screenshot