如何使用Seekbar将父布局背景模糊到所需程度。
setAlpha不是我的解决方案。我尝试了其他方法,但仅对ImageView起作用。但是我想模糊父布局背景而不影响子元素。
这是我的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/main_layout"
android:gravity="center"
android:layout_width="match_parent"
android:background="@drawable/forest2"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:text="@string/settings_message"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OK"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/blur_image"
/>
</LinearLayout>
public class BlurBackground extends Activity {
SeekBar blurimage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blur_layout_background);
blurimage=findViewById(R.id.blur_image);
blurimage.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}