【问题标题】:How to construct a button on runtime (Android) [closed]如何在运行时构建按钮(Android)[关闭]
【发布时间】:2013-05-19 15:27:56
【问题描述】:

文档中没有关于 Android 的这一特定功能的任何内容(例如这里:

http://developer.android.com/reference/android/widget/Button.html#Button(android.content.Context)

如何将按钮添加到现有布局(或在运行时创建布局)?

然后,如何将属性应用于我刚刚创建的按钮?

【问题讨论】:

  • 谷歌你在哪里?当我尝试时,数百次点击。
  • 搜索功能是你的朋友!
  • 好吧,你说得对,我搜索的不是很好,很抱歉提出了所谓的“无用”问题。

标签: java android android-layout android-view android-button


【解决方案1】:

您可以从代码中创建按钮。您可以在文档中找到设置属性的所有替代方法。例如

          Button button = new Button(this); 
          button.setText("hi"); 
          button.setId(Id);
          button.setTextColor(Color.Red);
          button.setBackgroundResource(R.drawable.icon);
          buttonlayout.addView(button); 

【讨论】:

  • 感谢您的回答。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 2011-07-19
相关资源
最近更新 更多