2012-05-07 8 views
-1

私は以下のリンクからの提案に従います How do I create a transparent Activity on Android? HTC Desireではアクティビティは透過的ですが、Moto MileStone(Android)では動作しません。背景は黒です。 私は以下のように解像度/値/のstyles.xmlを変更するが、モトマイルストーンでの背景は、まだ黒Android:透明なアクティビティが動作しない

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

答えて

0

である私はこれを試していないが、私は透明な背景を取得するための最良の方法は、色を追加することだと思います。

は16進

http://www.w3schools.com/html/html_colornames.aspで透明色を入れて...あなたはここで確認することができます。

答えを受け入れる場合は、右をクリックしてください。

問題があれば投稿してください。

+0

私もは、GetWindow()setBackgroundDrawable(新しいColorDrawable(0))を使用し、。しかし、あまりにも動作しませんでした –

0

アクティビティのOnCreateメソッドでは、プログラムでRGBA値をプログラムで設定できます。それはうまくいくかもしれない。最初の活動

私のXMLファイル:

+0

私は空のlinearlayoutを含む空のアクティビティを試して、私は#00000000にその背景を設定し、それは動作しません。 –

+0

あなたはこのようにあなたの活動にそれを設定しようとしません: 'myourview =(LinearLayout)findViewById(R.id.yourlayoutID); myourview.setBackgroundColor(Color.argb(0、0、0、0)); ' – Wottah

1

は、ここに私のソリューションです。ボタンをクリックすると、ボタンを持つ2番目のアクティビティにリダイレクトされます。

活動1:私は完全なソースコードを与えている

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button nextBtn = (Button)findViewById(R.id.button1); 
    nextBtn.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent("com.ranjan.dibya.shadow.Next")); 
     } 
    }); 
} 
} 

活動を2:

public class Next extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.next); 
} 
} 

活動1のためのXML:アクティビティ2用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#f09473" 
tools:context=".MainActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginRight="16dp" 
    android:text="Button" /> 

</RelativeLayout> 

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:text="This is clickable" /> 

</RelativeLayout> 
これは、私の作品

<style name="Theme.MyTranslucent" parent="android:style/Theme.Translucent"> 
    <item name="android:backgroundDimEnabled">true</item> 
    <item name="android:backgroundDimAmount">0.5</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:background">@android:color/transparent</item> 
</style> 

私のマニフェスト

<activity 
     android:name=".Next" 
     android:label="@string/app_name" 
     android:theme="@style/Theme.MyTranslucent" > 

スタイル。同じことがあなたのために働くことを願っています。

編集:あなたが続いリンクが中央にあるボタンで透明活動になります自分でこれを考え出した:)

関連する問題