2011-11-14 78 views
0

我有一个对话框出现在SurfaceView的顶部。我希望对话框有一个自定义图像作为背景,但我也想让图像稍微透明一点,以便在下面看到。android对话框 - 设置背景图像的不透明度

有关如何更改图像不透明度的任何想法?

gameover.xml:从父活动

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/dialog" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/imagebackground" 
    android:orientation="vertical" > 

创建代码

gameOverDialog = new Dialog(this); 
    gameOverDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    gameOverDialog.setContentView(R.layout.gameover); 

回答

1

你可能需要阿尔法添加到图像时创建它(在Photoshop ...等等)。但是你也可以试着将背景图像作为Drawable来获取,并调用setAlpha来获得你想要的。 http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setAlpha(int

+0

感谢您的回复。我尝试将背景设置为“Drawable”,并且工作正常。我不得不通过'gameOverDialog = new Dialog(this,android.R.style.theme_transulcent')来更改这行代码,但这会产生另一个问题,对话框将全屏显示。无论如何,感谢您的回答。 – Wozza