【问题标题】:change the button style in android code programmatically以编程方式更改android代码中的按钮样式
【发布时间】:2012-10-30 05:28:30
【问题描述】:

我希望以编程方式使用 android 代码更改按钮背景颜色、文本颜色、文本大小。

   Button btnLoadMore = new Button(this);
    btnLoadMore.setText("Load More");

    // Adding Load More button to lisview at bottom
    lv.addFooterView(btnLoadMore);

在上面的代码中成功设置了加载更多文本。但我必须写在下面的行

btnLoadMore.setTextColor("#FF1493");

表示出现以下错误

The method setTextColor(int) in the type TextView is not applicable for the arguments 

(字符串)

我该如何解决这个错误。请帮助我。

【问题讨论】:

标签: android android-layout android-button


【解决方案1】:

这样使用:

TextView text = (TextView) findViewById(R.id.text);
text.setTextColor(Color.parseColor("#FFFFFF"));

查看此链接:How to set the text color of TextView in code?

【讨论】:

  • 我必须使用以下行更改背景:btnLoadMore.setBackgroundResource(R.drawable.lgnbttn);它成功地为我工作
【解决方案2】:

试试:

Color.ParseColor("color hex value");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 2019-05-28
    • 2020-05-15
    • 1970-01-01
    • 2015-07-28
    相关资源
    最近更新 更多