2013-07-09 45 views
12

những gì tôi muốn đạt được là hoạt động có tính trong suốt giống như hộp thoại với khả năng hiển thị 100% nội dung RelativeLayout. Đây là xml hoạt động của:Hoạt động với nền trong suốt

<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> 

và điều này là hiển nhiên:

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

Ngay bây giờ nền vẫn có thể nhìn thấy, những gì tôi làm sai?

--- EDIT: tôi thêm

android:background="#c0000000" 

để LinearLayout. Bây giờ nền là minh bạch như tôi muốn, nhưng cũng TextViews bên trong RelativeLayout cũng minh bạch .. làm thế nào để thay đổi nó?

+0

bản sao có thể có của [Cách tạo hoạt động trong suốt trong Android?] (Http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android) – g00dy

+0

đặt android: background = " # 000000 "vào mã kiểm tra RelativeLayout – sweggersen

+0

trong liên kết hoạt động với tôi. http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android/38589105#38589105 –

Trả lời

1

Sau khi thiết lập tính minh bạch LinearLayout, hãy thử đặt độ trong suốt của con là giá trị bạn muốn. Điều này sẽ làm cho chúng có độ trong suốt khác với LinearLayout. Thử nó.

7

Cố gắng thiết lập

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

trong hoạt động của bạn.

Bạn cũng có thể thử để làm điều này trong một phong cách:

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

Cách tiếp cận thứ nhất không hoạt động ở bên cạnh tôi, thứ 2 cung cấp độ trong suốt nền đầy đủ + TextViews bên trong RelativeLayout là bán trong suốt, không đủ điều kiện – Mariusz

5

Thêm phong cách sau đây trong tập tin res/values/styles.xml của bạn (. Nếu bạn không có một, tạo ra nó) Đây là một tập tin hoàn chỉnh:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="Theme.Transparent" parent="android:Theme"> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@color/transparent</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    </style> 
</resources> 

(giá trị @color/transparent là giá trị màu #00000000 mà tôi đưa vào res/values/color.xml tập tin. các phiên bản sau của Android xác định một màu trong suốt cho bạn, vì vậy với những phiên bản bạn có thể sử dụng trực tiếp trong @android:color/transparent st YLE và bỏ qua bước color.xml (chú ý thêm android: trong định nghĩa))

Sau đó, áp dụng các phong cách để hoạt động của bạn, ví dụ:

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent"> 
... 
</activity> 

Taken từ here.

5

Tạo Phong cách

<style name="MyTransparentTheme" parent="android:Theme.Dialog"> 
     <item name="android:windowIsTranslucent">true</item> 
     <item name="android:windowBackground">@android:color/transparent</item> 
     <item name="android:windowContentOverlay">@null</item> 
     <item name="android:windowNoTitle">true</item> 
     <item name="android:windowIsFloating">true</item> 
     <item name="android:backgroundDimEnabled">false</item> 

đây là manifest:

<activity 
      android:name="your package.activity" 
      android:theme="@style/MyTransparentTheme"> 
     </activity> 
+0

hoạt động tốt - được thử nghiệm trên Android 5.0.1 –

+0

không hoạt động kể từ ngày này –

3

tôi thêm android: background = "# c0000000" để LinearLayout. Bây giờ nền là minh bạch như tôi muốn, nhưng cũng TextViews bên trong RelativeLayout cũng trong suốt .. làm thế nào để thay đổi nó?

Thêm nền chắc chắn vào phần tử RelativeLayout của bạn. Bằng cách này, RelativeLayout sẽ có nền tảng vững chắc và chỉ có lợi nhuận trong suốt.

Các vấn đề liên quan