В следующем коде показано диалоговое окно, но ссылка недоступна для щелчка.
Код: Выделить всё
public void showNews(int number) {
int last = shared.getInt("news", 1);
Log.d("News", String.valueOf(last));
if (last >= number) return;
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this, R.style.darkAlertDialog); //, R.style.darkAlertDialog
builder.setTitle("Application News");
StringBuilder text = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(getAssets().open("html/" + "news.html")));
String mLine;
while ((mLine = reader.readLine()) != null) {
text.append(mLine);
text.append('\n');
}
} catch(IOException e) {
Toast.makeText(getApplicationContext(), "Error reading file!", Toast.LENGTH_LONG).show();
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch(IOException e) {
Log.e("showNews", "Error reading file");
return;
}
}
}
// Trouble
Spanned result;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
result = Html.fromHtml(text.toString(), Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(text.toString());
}
builder.setMessage(result);
// result.setMovementMethod(LinkMovementMethod.getInstance());
// result.setClickable(true);
// Trouble
builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {@Override
public void onClick(DialogInterface dialog, int which) {
// prefs.putInt("news", number);
// prefs.apply();
dialog.dismiss();
}
});
builder.create();
builder.show();
}
Если я заменю раздел между // Проблема, как предложено в разделе «Использование HTML в диалоговом окне оповещений Android» на
Код: Выделить всё
TextView msg = new TextView(this);
msg.setText(Html.fromHtml(String.valueOf(text)));
builder.setView(msg);
msg.setMovementMethod(LinkMovementMethod.getInstance());
msg.setClickable(true);

Я также пробовал использовать собственный макет, но он оказывается пустым, хотя файлы журналов показывают, что текст есть.
Код: Выделить всё
Код: Выделить всё
Log.d("text", String.valueOf(text));
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this, R.style.darkAlertDialog); //, R.style.darkAlertDialog
builder.setTitle("Application News");
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.app_news, null);
final TextView appNews = dialogView.findViewById(R.id.textNews);
appNews.setText(result);
appNews.setMovementMethod(LinkMovementMethod.getInstance());
appNews.setClickable(true);
Log.d("msg", String.valueOf(appNews.getText()));
builder.setView(dialogView);

Подробнее здесь: https://stackoverflow.com/questions/798 ... -clickable
Мобильная версия