英文:
Design TextView to look like a AlertDialog
问题
我正在尝试创建一个新的 TextView,它看起来像一个具有 AlertDialogTheme 样式的 AlertDialog,使用以下构造函数:
public TextView (Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
我已经尝试将 R.attr.alertDialogTheme 添加到参数 defStyleAttr,将 R.style.AlertDialogTheme 添加到参数 defStyleRes,但没有成功。我是否错误地使用了这些值?提前感谢!
英文:
I'm trying to create a new TextView that looks like a AlertDialog with a style of AlertDialogTheme using this constructor
public TextView (Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
I tried already adding R.attr.alertDialogTheme to the parameter defStyleAttr and R.style.AlertDialogTheme to parameter defStyleRes but it didn't work. Am I using the values wrong? Thanks in advance!
答案1
得分: 0
以下是翻译好的部分:
第一,你可以创建自己的TextView
并使其中的一部分文本链接化:
val message = TextView(context)
// R.string.dialog_message => "Test this dialog following the link to google.com"
val spannable = SpannableString(R.string.dialog_message)
Linkify.addLinks(spannable, Linkify.WEB_URLS)
message.text = spannable
message.movementMethod = LinkMovementMethod.getInstance()
返回AlertDialog
.Builder(context)
.setView(message)
.create()
第二,你可以在你的AlertDialog消息中使用类似以下的HTML文本:
Html.fromHtml("<a href='https://play.google.com/store/apps/details?id=com.xxxxxxxxx'>Click Here</a>")
第三,你可以创建一个扩展Dialog类的DialogFragment,并填充你自己的视图,以下是如何做的参考链接:
如果有帮助,请告诉我。
英文:
There are multiple things you could try out:
First you could create your own textview and make linkify the part of your textview
val message = TextView(context)
// R.string.dialog_message =>
// "Test this dialog following the link to google.com"
val spannable = SpannableString(R.string.dialog_messag)
Linking.addLinks(spannable,
Linkify.WEB_URLS)
message.text = spannable
message.movementMethod =
LinkMovementMethod.getInstance()
Return Alertdialog
.Builder(context)
.setView(message)
.create()
Secondly you could use in your alertDialogs message an html text like this:
Html.fromHtml("<a href='https://play.google.com/store/apps/details?id=com.xxxxxxxxx'>Click Here</a>")
Third you could create a dialogFragment which extends the Dialog class and inflate your own view, here is a reference on how to do that:
https://medium.com/@huseyinozkoc/how-to-use-dialogfragment-in-android-f8095dd0993f
Let me know if it helped
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论