简体   繁体   English

如何将android按钮更改为深灰色而不是浅灰色

[英]How can I change the android button to dark grey instead of light grey

I would like to change the color of the android button in my application to be dark grey instead of light grey. 我想将应用程序中android按钮的颜色更改为深灰色而不是浅灰色。 I intent to keep the color of the focus/pressed the same. 我打算保持焦点/按下的颜色不变。 I just want to change the color of the button in 'normal' state to dark grey. 我只想将“正常”状态下的按钮颜色更改为深灰色。

I have found this thread: Standard Android Button with a different color 我发现了这个线程: 具有不同颜色的标准Android按钮

I think the easiest way is to do this. 我认为最简单的方法是这样做。 Is that correct? 那是对的吗? But how can I make the LightingColor Filter to make it darkgrey? 但是,如何使LightingColor滤镜使其变为深灰色?

button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));

I have tried 我努力了

button.getBackground().setColorFilter(new LightingColorFilter(0xffffffff, 0xFF3A3A3A));

But all I get is a white color. 但是我得到的只是白色。

That's similar to what I am doing in my TabHost tabs in XML. 这类似于我在XML的TabHost选项卡中所做的事情。 If you have custom buttons and graphics it can be done in Java, but it is much easier if you're able to do it in your XML. 如果您具有自定义按钮和图形,则可以用Java来完成,但是如果能够以XML进行,则要容易得多。

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/settings"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/mountain" />
</selector>

You could use the default light theme 您可以使用默认的灯光主题
Example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 微调框有灰色文字,为什么? 如何将其更改为默认文本颜色? - Spinner has Grey Text, why? How can I change it to default text colour instead? Android-如何更改由BitmapDrawable创建的灰色背景 - Android - How to change grey background created by a BitmapDrawable 如何使按钮变灰? - How to grey out a button? 将图像导入Android Studio,显示为深灰色 - Importing image into Android Studio, appears as dark grey 为什么当我创建这个新的位图时其背景是深灰色? 如何将其设置为布局背景的相同颜色? - Why when I create this new Bitmap its background is dark grey? How can I set it to the same color of the layout background? 如何在Android上的Dark App Bar上使用Light SearchView? - How can I use Light SearchView on Dark App Bar on android? 如何在Android中使微调器变灰? - How to grey out spinner in Android? Android:如何“显示”单选按钮 - Android: How to 'grey out' a radiobutton 如何在android中将谷歌地图标记颜色更改为灰色 - How to change the google maps marker color to grey in android 如何在Android中更改警报对话框的默认灰色 - How to change the default grey color of the alert dialog box in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM