简体   繁体   English

设置 Android Studio 预览背景色

[英]Setting Android Studio preview background color

I'm creating a custom view that is supposed to go on top of my other views inside a normal layout/view.我正在创建一个自定义视图,该视图应该位于普通布局/视图中的其他视图之上。 I want it to be a half-transparent white color, so that what's behind it is still visible and I want it to contain fully solid white borders and white font color.我希望它是半透明的白色,以便它后面的内容仍然可见,我希望它包含完全纯白色边框和白色字体颜色。 On a black/dark background, this is easily readable.在黑色/深色背景上,这很容易阅读。 However, in the preview, which has a white background, I'm not able to see anything.但是,在具有白色背景的预览中,我什么也看不到。

Is there a way to change the background color of the preview, so that I can't test the look of my custom view?有没有办法更改预览的背景颜色,以便我无法测试自定义视图的外观?

If possible, I'd like to achieve that without adding unnecessary components that imitate a black background.如果可能的话,我想在不添加模仿黑色背景的不必要组件的情况下实现这一目标。

Ok, I just stumbled over it by accident:好吧,我只是偶然发现了它:

Put xmlns:tools="http://schemas.android.com/tools in the root xml bracket of your layout.xmlns:tools="http://schemas.android.com/tools放在布局的根 xml 括号中。

After that, you can use tools:background= to set your background as you like it.之后,您可以使用tools:background=设置您喜欢的背景。 This also works with other attributes.这也适用于其他属性。

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

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