Android 在安卓系统中,点击工具栏上的图标后,如何使整个布局呈现半透明(半透明)外观,并使其恢复正常?
当我的应用程序打开时,我需要将布局设置为半透明,并在单击工具栏中设置的和图标后使其恢复正常。在xml布局中为模糊图像设置alpha。您可以从背景图像或视图创建模糊位图,然后将其设置为背景。我使用下面的类创建了模糊位图位图Android 在安卓系统中,点击工具栏上的图标后,如何使整个布局呈现半透明(半透明)外观,并使其恢复正常?,android,Android,当我的应用程序打开时,我需要将布局设置为半透明,并在单击工具栏中设置的和图标后使其恢复正常。在xml布局中为模糊图像设置alpha。您可以从背景图像或视图创建模糊位图,然后将其设置为背景。我使用下面的类创建了模糊位图位图 import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.support.v8.renderscript.Allo
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.view.View;
public class BlurBuilder {
private static final float BITMAP_SCALE = 0.2f;
private static final float BLUR_RADIUS = 20f;
public static Bitmap blur(View v) {
return blur(v.getContext(), getScreenshot(v));
}
public static Bitmap blur(Context ctx, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(ctx);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
private static Bitmap getScreenshot(View v) {
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
}
然后
在MainActivity.java中
在下面一行添加声明
公共线性布局线性布局
在onCreate of MainActivity.java中添加以下两行
并在图标的onclick上写下一行,在其onclick上,您需要使其再次看起来正常
linearlayout.setAlpha((float) 1);
那么你面临什么问题?你尝试过什么吗?阿尔法?对于模糊效果?是的。或者你也可以看到这个链接。你知道什么是alpha吗?它与图像模糊有何关系?在xml:android:alpha=0.5或代码yourView.getBackground.setAlpha100中@实际上,您也可以从mainActivity.java设置alpha。将其设置为linearlayout.setAlphafloat 0.5以使其模糊,并写入linearlayout.setAlphafloat1以使其再次完全正常。。。。。。。。。0使它完全透明,我不确定关于0。
linearLayout=(LinearLayout) findViewById(R.id.layout_main);
linearLayout.setAlpha((float) 0.5);
linearlayout.setAlpha((float) 1);