Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

android - Activity with transparent background

what I want to achieve is activity with dialog-like transparency with 100% visibility of RelativeLayout content. This is activity's xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
        android:layout_marginTop="50dip">
        (...)
    </RelativeLayout>
</LinearLayout>

and this is manifest:

<activity
        android:name="com.acentic.rcontrol.activities.MyActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>

Right now background is still visible, what am I doing wrong?

--- EDIT: I added

android:background="#c0000000"

to LinearLayout. Now background is transparent as I wanted to, but also TextViews inside RelativeLayout are also transparent.. how to change it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to set

    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

in your activity.

You can also try to do this in a style:

 <style name="AppTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
</style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...