0
有谁知道如何以编程方式变暗View's
背景,如alertDialog
或NavigationDrawer
这样做?我需要背景与ToolBar
(1)和StatusBar
重叠,但StatusBar
的图标应该可见(2)。在我的情况下,它不应该是dialog
。例如,我必须加深Button
或CustomView
的背景。Android变暗背景
有谁知道如何以编程方式变暗View's
背景,如alertDialog
或NavigationDrawer
这样做?我需要背景与ToolBar
(1)和StatusBar
重叠,但StatusBar
的图标应该可见(2)。在我的情况下,它不应该是dialog
。例如,我必须加深Button
或CustomView
的背景。Android变暗背景
我一直在寻找这个问题的答案很长一段时间,但最后我找到了解决办法。
我研究了代码“DialogPlus”库,找出关键点。
getWindow().getDecorView();
final LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
final View background = inflater.inflate(R.layout.frame, null);
final Animation a = AnimationUtils.loadAnimation(this, R.anim.in);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ViewGroup decorView = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
decorView.addView(background);
background.startAnimation(a);
}
});
背景resoource文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="0.5"></FrameLayout>
</LinearLayout>