请注意,我使用的是Mono for Android
我有一个ListView项目可以通过单击列表底部的“更多”按钮进行扩展。该列表以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
任何建议都表示赞赏!
答案 0 :(得分:1)
我也搜索了这个问题的答案。这似乎是一个Android错误,因为我没有找到适用于创建视图的样式方式。 为什么不想给TextView充气呢? 像这样:
<强>布局/ my_view.xml 强>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:style="@style/more_button" />
<强>活动强>
TextView mMoreProductsButton = (TextView) getLayoutInflater().inflate(R.layout.my_view, null, false);
抱歉,我不知道Mono是否可行。