简体   繁体   English

在android中将形状背景设置为透明

[英]set shape background to transparent in android

I have a shape drawable that I want to use as a background. 我有一个可绘制的形状,我想用作背景。 I want the shape to be transparent. 我希望形状是透明的。 But so far it's not. 但到目前为止还没有。 How do I do that? 我怎么做? Here is what I have: 这是我有的:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

    <solid android:color="#80000000" />

    <stroke
        android:width="1dip"
        android:color="#000000" />

    <corners android:radius="10dp" />

</shape>

I expected the line <solid android:color="#80000000" /> to do the trick. 我期望行<solid android:color="#80000000" />来做这个伎俩。

EDIT: 编辑:

In manifest, I set android:theme="@android:style/Theme.Dialog" . 在清单中,我设置了android:theme="@android:style/Theme.Dialog" Could that be the cause of the problem? 这可能是问题的原因吗? I am basically trying to get this view on top of another. 我基本上试图将这个观点置于另一个之上。 Changing to 00 or FF or whatever else does not work. 更改为00或FF或其他任何不起作用。

如果要将形状背景设置为透明,则需要设置此颜色

<solid android:color="#00000000" />

for creating a color including an opacity effect, you can create a color with taking the alpha channel into account. 要创建包含不透明度效果的颜色,您可以考虑使用Alpha通道创建颜色。

<resources>
<color name="translucent_grey">#88cccccc</color>
</resources>

a quote from another User about the color formats: 另一位用户关于颜色格式的引用:

When defining the color of a view in android, the format can be either #RRGGBB or #AARRGGBB, where AA is the hex alpha value. 在android中定义视图的颜色时,格式可以是#RRGGBB或#AARRGGBB,其中AA是十六进制alpha值。 FF would be fully opaque and 00 would be full transparent. FF将完全不透明,00将完全透明。

more information about this technique can be found in this thread: How to Set Opacity (Alpha) for View in Android 有关此技术的更多信息,请参见此主题: 如何在Android中为View设置不透明度(Alpha)

Regards, Jim 问候,吉姆

You can use this : 你可以用这个:

<solid
    android:color="@android:color/transparent"/>

This is working for me. 这对我有用。

I found the answer. 我找到了答案。 Direct quote: 直接报价:

The easiest way that I have found is to set the activity's theme in the AndroidManifest to android:theme="@android:style/Theme.Holo.Dialog" then in the activity's onCreate method call getWindow().setBackgroundDrawable(new ColorDrawable(0)); 我找到的最简单的方法是将AndroidManifest中的activity主题设置为android:theme =“@ android:style / Theme.Holo.Dialog”然后在activity的onCreate方法中调用getWindow()。setBackgroundDrawable(new ColorDrawable(0 ));

from @DrewLeonce in Android: how to create a transparent dialog-themed activity 来自Android中的 @DrewLeonce :如何创建透明的对话主题活动

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

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