Android TextView defStyle 参数被忽略?
请注意,我使用的是 Android 版 Mono
我有一个项目列表视图,可以通过单击列表底部的“更多”按钮来扩展这些项目。该列表是在 XML 中定义的,但“更多”按钮只是一个可单击的 TextView,通过 AddFooterView 添加到列表底部。我试图将预定义的样式应用于运行时创建的 TextView,但它不起作用。
mMoreProductsButton = new TextView(this, null, Resource.Style.more_button);
mMoreProductsButton.Text = "More";
mMoreProductsButton.Click += new EventHandler(MoreProductsButton_Click);
mListView.AddFooterView(mMoreProductsButton);
TextView 文档显示了此签名: TextView(Context context, AttributeSet attrs, int defStyle)
defStyle
在文档中定义为应用于视图的默认样式。我在其他地方看到的一个示例将 null 作为 AttributeSet 传递,但我不确定这是否有效或与我的问题相关。
我发现了这个错误,但不确定它是否相关且是最新的: http://code.google.com/p/android/issues/detail ?id=12683
如有任何建议,我们将不胜感激!
Note that I am using Mono for Android
I have a ListView of items that can be extended by clicking a "More" button at the bottom of the list. The list is defined in XML but the more button is simply a clickable TextView that is added to the bottom of the list via AddFooterView. I am trying to apply a pre-defined style to the runtime-created TextView but it is not working.
mMoreProductsButton = new TextView(this, null, Resource.Style.more_button);
mMoreProductsButton.Text = "More";
mMoreProductsButton.Click += new EventHandler(MoreProductsButton_Click);
mListView.AddFooterView(mMoreProductsButton);
TextView documentation shows this signature: TextView(Context context, AttributeSet attrs, int defStyle)
defStyle
is defined in the documentation as the default style to apply to the view. An example I saw elsewhere passed null as the AttributeSet but I'm not sure if that is valid or related to my problem.
I found this bug and am not sure if it is related and current:
http://code.google.com/p/android/issues/detail?id=12683
Any suggestions are appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也搜索了这个问题的答案。这似乎是一个 Android 错误,因为我没有找到一种应用于创建视图的样式方式。
为什么你不想膨胀你的 TextView?
像这样:
layout/my_view.xml
Activity
抱歉,我不知道它在 Mono 中是否可行。
I also searched answer to this question. It seems to be an Android bug because I didn't found a way of style applying to creating Views.
Why don't you want to inflate your TextView?
Like this:
layout/my_view.xml
Activity
Sorry, I don't know if it workable in Mono.