pro*_*eek 5 c# mono android textview xamarin.android
请注意,我使用的是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);
Run Code Online (Sandbox Code Playgroud)
TextView文档显示了此签名: TextView(Context context, AttributeSet attrs, int defStyle)
defStyle
在文档中定义为要应用于视图的默认样式.我在别处看到的一个例子将null作为AttributeSet传递,但我不确定它是否有效或与我的问题有关.
我发现了这个错误,我不确定它是否相关且最新:http: //code.google.com/p/android/issues/detail?id = 12683
任何建议表示赞赏!
我也搜索了这个问题的答案。这似乎是一个 Android 错误,因为我没有找到一种应用于创建视图的样式方法。为什么你不想膨胀你的 TextView 呢?
像这样:
布局/my_view.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:style="@style/more_button" />
Run Code Online (Sandbox Code Playgroud)
活动
TextView mMoreProductsButton = (TextView) getLayoutInflater().inflate(R.layout.my_view, null, false);
Run Code Online (Sandbox Code Playgroud)
抱歉,我不知道它在 Mono 中是否可行。
归档时间: |
|
查看次数: |
1001 次 |
最近记录: |