我想要做的是,将一个线性布局设置为半透明模糊的背景。目前,我有一个完全黑色的线性布局,覆盖了一些需要购买钥匙才能查看的信息。然而,我希望它被模糊处理,而不是完全覆盖,因为这会破坏布局。它需要保持在那里,只是模糊和不可读。谢谢您的帮助!
我不确定LinearLayout。但是对于你的活动,你可以尝试这个。
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
并使用setContentView(R.layout.your_layout);
方法。
试试GLSurfaceView怎么样:
http://developer.android.com/resources/articles/glsurfaceview.html
在Android SDK中,有一个关于获取半透明表面的示例(app/TranslucentActivity.java),本质上是设置alpha通道:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create our Preview view and set it as the content of our
// Activity
mGLSurfaceView = new GLSurfaceView(this);
// We want an 8888 pixel format because that's required for
// a translucent window.
// And we want a depth buffer.
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
// Tell the cube renderer that we want to render a translucent version
// of the cube:
mGLSurfaceView.setRenderer(new CubeRenderer(true));
// Use a surface format with an Alpha channel:
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
setContentView(mGLSurfaceView);
}
关于使用 Alpha 通道的其他线程,请参考以下内容:
另一个示例是应用程序/TranslucentBlurActivity.java(来自 Android SDK):
public class TranslucentBlurActivity extends Activity {
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
@Override
protected void onCreate(Bundle icicle) {
// Be sure to call the super class.
super.onCreate(icicle);
// Have the system blur any windows behind this one.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
// See assets/res/any/layout/translucent_background.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.translucent_background);
}
}
FLAG_BLUR_BEHIND
已被弃用。 - Ayoub android:background="@null"
对于EditText,它对我有效。据我所知,它应该适用于任何视图。因此,请尝试一下这个。