当我们显示 DialogFragment 时,我们如何更改背景的前景色,例如当我们在 evernote 或 messenger 应用程序中单击 fab 时,我知道这样做的方式可能会有所不同,但这就是我正在寻找的那种效果
最佳答案
我找到了解决这个问题的方法。这是代码。
在styles.xml 中设计一个自定义主题。
样式.xml
<style name="AppTheme.CustomTheme">
<item name="android:windowIsFloating">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
在 list 文件中,在弹出窗口中使用此样式。
安卓 list
<activity android:name=".DialogDesign"
android:theme="@style/AppTheme.CustomTheme"
android:screenOrientation="portrait"></activity>
在 layout.xml 文件中使用 3 个不同的 relativeLayouts,一个作为 root,另一个作为淡入淡出的背景,另一个作为弹出窗口。
activity_dialog_design.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DialogDesign">
<RelativeLayout
android:id="@+id/fadedBg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#7fffffff"
android:layout_margin="0dp"/>
<RelativeLayout
android:layout_width="300dp"
android:layout_height="500dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="100dp"
android:layout_marginBottom="100dp"
android:layout_centerHorizontal="true"
android:background="@android:color/white"/>
</RelativeLayout>
在activity.java 文件中设置褪色窗口的高度和宽度。
DialogDesign.java
public class DialogDesign extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog_design);
RelativeLayout fadedBg=(RelativeLayout)findViewById(R.id.fadedBg);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = 1800;
params.width = 1100;
this.getWindow().setAttributes(params);
}
}
在那里,完成了!在最内部的相对布局中添加您想要添加的任何内容。
关于java - Android:更改背景颜色显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36609866/