简体   繁体   English

Android开发:使用Java更改背景Tinton按钮

[英]Android Development: Changing Background Tinton Button with Java

So I am working on an app using android studio, and in the XML file, I realized if you edit the android:BackgroundTint of a button, you can change the color or the button, however, I wanted to change this within my java code, and I cannot figure out how to do this. 所以我正在使用android studio开发一个应用程序,并且在XML文件中,我意识到如果您编辑按钮的android:BackgroundTint,则可以更改颜色或按钮,但是,我想在我的Java代码中更改它,我不知道该怎么做。 The reason I dont just simply change android:BackgroundColor is that that changes the overall shape and effect of the button, and I do not want to sacrifice this. 我不只是简单地更改android:BackgroundColor的原因是,它更改了按钮的整体形状和效果,因此我不想牺牲这一点。 Any help to solve this is greatly appreciated. 任何帮助解决此问题的方法将不胜感激。

Figured it out. 弄清楚了。 This is the code I was looking for: 这是我正在寻找的代码:

button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); button.getBackground()。setColorFilter(0xFFFF0000,PorterDuff.Mode.MULTIPLY);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM