我有一个 Eula 对话框,其中包含一个我 addLinks 的文本视图,以便在文本字符串中识别链接。我正在使用 dpad 导航,如果焦点位于链接上,则需要突出显示链接。有没有办法向 onFocus 的链接添加状态?我也可以将焦点指向正面和负面按钮吗?这是方法:
public static boolean show(final Activity activity) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
if (!preferences.getBoolean(ACCUWX.Preferences.PREFERENCE_EULA_ACCEPTED, false)) {
final TextView message = new TextView(activity);
final SpannableString s = preferences.getString(ACCUWX.Preferences.PREF_PARTNER_CODE, null).equals(ACCUWX.PartnerCodes.TMOBILE_PARTNER_CODE)
|| preferences.getString(ACCUWX.Preferences.PREF_PARTNER_CODE, null).equals(ACCUWX.PartnerCodes.TMOBILE_7_PARTNER_CODE)?
new SpannableString(activity.getText(R.string.eula_terms_info_tmobile))
: new SpannableString(activity.getText(R.string.eula_terms_info));
Linkify.addLinks(s, Linkify.WEB_URLS);
message.setPadding(10, 10, 10, 10);
message.setText(s);
message.setMovementMethod(LinkMovementMethod.getInstance());
if (ad == null) {
ad = new AlertDialog.Builder(activity)
.setTitle(R.string.terms_conditions)
.setCancelable(false)
.setPositiveButton(R.string.agree, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
accept(preferences);
if (activity instanceof OnEulaAgreedTo) {
((OnEulaAgreedTo) activity).onEulaAgreedTo();
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
refuse(activity);
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
refuse(activity);
}
})
.setView(message)
.create();
ad.show();
}
return false;
}
return true;
}
我不知道如何向 txt 中的链接添加状态,而不是它们自己的单独视图。
*****编辑***** 如果我添加这行代码: message.setLinkTextColor(R.color.link_text); 然后我的链接不可见。但这告诉我它至少可以识别链接。这是存储在 res/color 中的应用的 ColorStateList (link_text.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff33ff"/> <!-- focused -->
<item android:color="#00ff00"/> <!-- default -->
</selector>
这是屏幕截图: