c# - Android TextView defStyle 参数被忽略?

标签 c# android mono textview xamarin.android

请注意,我正在为 Android 使用 Mono

我有一个项目 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 在文档中定义为应用于 View 的默认样式。我在别处看到的一个示例将 null 作为 AttributeSet 传递,但我不确定这是否有效或是否与我的问题相关。

我发现了这个错误,但不确定它是否相关并且是最新的: http://code.google.com/p/android/issues/detail?id=12683

如有任何建议,我们将不胜感激!

最佳答案

我也搜索了这个问题的答案。这似乎是一个 Android 错误,因为我没有找到一种将样式应用于创建 View 的方法。 你为什么不想膨胀你的 TextView?
像这样:

layout/my_view.xml

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:style="@style/more_button" />

Activity

TextView mMoreProductsButton = (TextView) getLayoutInflater().inflate(R.layout.my_view, null, false);

抱歉,我不知道它是否适用于 Mono。

关于c# - Android TextView defStyle 参数被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7772472/

相关文章:

c# - Process.Start() 创建的进程在父应用程序关闭时终止

c# - 如何在 .NET 中为我的应用程序创建配置文件

android - eclipse 安卓 : I want a letter appear firSTLy bigger and then getting smaller

android - 在Android Market中托管GPL代码(dcm4che库)

c# - 使用 C# 和 Mono 为 OS X 构建 Cocoa UI

c# - ConfigurationManager.ConnectionStrings ["aaa"].ConnectionString 将 127.0.0.1 替换为 localhost

c# - 如何使用 yield 在并行 block 或任务中返回 Item 的集合

c# - 全文搜索jquery-高亮黄色背景

c# - 使用反射 C# 将动态对象转换为类型

java - onCreate() 和 onClick() 的顺序