2014-10-17 697 views
1

我希望我的活動看起來像一個大型的對話框,透明的東西說四邊都是四分之一,中間部分是堅固的,我可以放置視圖。 我以爲使用框架佈局將是一個框架佈局內的另一個答案,但我無法使第一個透明。使FrameLayout透明

我的XML文件: -

<?xml version="1.0" encoding="utf-8"?> 


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#00000000" > 

    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="50dp" 
     android:layout_marginLeft="75dp" 
     android:layout_marginRight="75dp" 
     android:layout_marginTop="50dp" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:text="Search" /> 

      <EditText 
       android:id="@+id/editText1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/button1" 
       android:layout_alignParentLeft="true" 
       android:layout_marginBottom="30dp" 
       android:gravity="center" 
       android:hint="Enter Movie Name!" /> 

      <ProgressBar 
       android:id="@+id/progressBar1" 
       style="?android:attr/progressBarStyleLarge" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/editText1" 
       android:layout_centerHorizontal="true" /> 

     </RelativeLayout> 

    </FrameLayout> 


</FrameLayout> 

它不工作。有任何想法嗎?

+0

你在找這樣的事嗎? http://imgur.com/dBCM9WR – aProperFox 2014-10-17 15:55:54

+0

是的,那就是我想要的。 – Mohit 2014-10-17 15:58:21

回答

0

你必須設置該活動的主題是這樣的:

Manifest.xml

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

res/values/styles.xml

<style name="Theme.Transparent" parent="Theme.MCChilli.NoTitle"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
</style> 

另外,我覺得這個答案是隻有幾個谷歌點擊了但無論...

+0

這不會使整個活動變得透明,我只想讓一部分變得透明。 – Mohit 2014-10-17 16:17:48

+0

不是你想要的嗎? '我希望我的活動看起來像是一種大對話'?! – dominik4142 2014-10-17 16:20:05

+0

對話框在中間是可靠的,我們可以看到所有四面都有背景,你的代碼使整個活動變得透明 – Mohit 2014-10-17 16:23:51

1

我有同樣的問題。我解決了它通過使用:

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

我不知道它爲什麼只能以編程方式工作。

找到這個here(在最後)。