Android按钮背景颜色(Android button background color)

我想在我的应用程序中设置按钮的背景颜色,我无法实现我想要的结果...

我试图设置的颜色是holo_green_light(#ff99cc00) 。 为了做到这一点,我使用setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);

我得到的颜色不是holo_green_light而是lightgrey和holo_green_light的混合。

我已经尝试使用LightingColorFilter但没有取得太大的成功。

有没有办法以编程方式做到这一点,使按钮看起来像一个按钮,而不是一个平面矩形与我需要的颜色。

I am trying to set the background color of a button in my app and I am unable to achieve the result that I want...

The color that I am trying to set is holo_green_light(#ff99cc00). In order to do it, I am using setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);

The color that I get is not the holo_green_light but a mix of lightgrey and holo_green_light.

I have tried using the LightingColorFilter without much success.

Is there a way to do it programatically, so that the button appears like a button and not a flat rectangle with the color that I need.



按钮比只改变一种颜色更复杂...

Android按钮是使用相当多的9个补丁和状态可绘制的。 你应该看看Android Holo Colors来生成这些颜色 ,你会想选择“颜色按钮”,它会为你生成必要的图像&xml ...

Buttons are more complex than just changing one color...

Android buttons are made using quite a few 9-patches and state drawables. You should take a look at Android Holo Colors to generate those, you would want to select "Color Button" and it will generate the necessary images & xml for you...

2013-08-06

相关问答

不幸的是我不知道如何检索实际的颜色。 将它作为Drawable很容易 Button button = (Button) findViewById(R.id.my_button);

Drawable buttonBackground = button.getBackground();

如果你知道这是一种颜色,那么你可以尝试 ColorDrawable buttonColor = (ColorDrawable) button.getBackground();

如果您使用的是Android 3.0+

...

按钮比只改变一种颜色更复杂... Android按钮是使用相当多的9个补丁和状态可绘制的。 你应该看看Android Holo Colors来生成这些颜色 ,你会想选择“颜色按钮”,它会为你生成必要的图像&xml ... Buttons are more complex than just changing one color... Android buttons are made using quite a few 9-patches and state drawables. You shoul

...

此行为是Holo主题的默认Android样式按钮,此类按钮的选择器使用位于sdk \ platforms \ android-16 \ data \ res \ drawable的路径中,其名称如下: btn_default_holo_dark.xml和btn_default_holo_light.xml 用于第一个选择器的drawable是: btn_default_normal_holo_dark.9

btn_default_disabled_holo_dark.9

btn_default

...

这是一个可绘制的示例,默认情况下将为白色,按下时为黑色: <?xml version="1.0" encoding="utf-8"?>

android:color="#1E669B

...

我不确定这是否有效(但值得一试): 尝试在onClick()语句中初始化color = new Random()。 b.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

color = new Random();

p.setARGB(256,color.nextInt(256),color.nextInt(256),color.

...

如果要在按下或聚焦按钮时更改背景,请在此处查看如何为每个状态创建自定义背景(状态为按下按钮,聚焦,选择等)。 如果您只想在经过一段时间后更改背景,请参阅使用处理程序: final Handler handler = new Handler();

handler.postDelayed(new Runnable() {

@Override

public void run() {

//This will run after 1000 (defined below) millisecon

...

尝试将tablelayout放入FrameLayout,如下所示:  

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="f

...

使用这个文件可绘制 <?xml version="1.0" encoding="utf-8"?>

...

创建一个新的 drawable custom_button.xml <?xml version="1.0" encoding="utf-8"?>

...

我认为您需要将属性从“主题”更改为“样式”。 这些文件适用于不同的东西,因此使用方式不同。 样式用于为各个视图或组件分配属性,而Theme用于将属性应用于整个应用程序。 所以试试这个:  

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/btnLogin"

android:id="@+id/btn_login"

...