[英]Background not transparent on API 19
I'm not able to set the background transparent on API 19, instead I get a white background. 我无法在API 19上将背景设置为透明,而是获得了白色背景。 The background is only transparent on API 21 and above.
背景仅在API 21及更高版本上是透明的。
I have an activity that calls a custom dialog fragment. 我有一个调用自定义对话框片段的活动。 The parent layout of dialog fragment has
background="@android:color/transparent"
. 对话框片段的父布局具有
background="@android:color/transparent"
。
What am I doing wrong? 我究竟做错了什么? Am I missing something.
我错过了什么吗? Any tips of hint would be really helpful.
提示的任何提示将非常有帮助。
Solutions that I have tried: 我尝试过的解决方案:
Changing primary color to transparent on MyActivityTheme 在MyActivityTheme上将原色更改为透明
Parent layout background="@null"
父级布局
background="@null"
Dialog with transparent background in Android Android中具有透明背景的对话框
How to make any view background transparent? 如何使任何视图背景透明?
https://mindofaandroiddev.wordpress.com/2013/12/28/making-the-status-bar-and-navigation-bar-transparent-with-a-listview-on-android-4-4-kitkat/ https://mindofaandroiddev.wordpress.com/2013/12/28/making-the-status-bar-and-navigation-bar-transparent-with-a-listview-on-android-4-4-kitkat/
MyDialogFragment MyDialogFragment
public class MyDialogFragment : DialogFragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle(DialogFragmentStyle.NoTitle, Resource.Style.MyDialogTheme);
}
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
var builder = new AlertDialog.Builder(Activity);
var inflater = Activity.LayoutInflater;
var dialogView = inflater.Inflate(Resource.Layout.MyDialogLayout, null);
if (dialogView != null)
{
builder.SetView(dialogView);
}
var dialog = builder.Create();
dialog.Window.RequestFeature(WindowFeatures.NoTitle);
dialog.Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
return dialog;
}
}
MyDialogLayout MyDialogLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Child layouts -->
</LinearLayout>
Styles.xml Styles.xml
<style name="MyActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/Red</item>
<item name="colorAccent">@color/White</item>
<item name="colorControlNormal">@color/White</item>
<item name="colorControlActivated">@color/White</item>
<item name="android:textColorHint">@color/White</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="MyDialogTheme" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorAccent">@color/Red</item>
<item name="colorControlNormal">@color/Red</item>
<item name="colorControlActivated">@color/Red</item>
<item name="colorControlHighlight">@color/Red</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textColorPrimary">@color/Red</item>
</style>
I think you need to add this code in your OnResume() method : 我认为您需要在OnResume()方法中添加以下代码:
public override void OnResume()
{
base.OnResume();
// Auto size the dialog based on it's contents
Dialog.Window.SetLayout(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);
Dialog.Window.SetGravity(GravityFlags.Bottom);
// Make sure there is no background behind our view
Dialog.Window.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
// Disable standard dialog styling/frame/theme: our custom view should create full UI
SetStyle(Android.Support.V4.App.DialogFragment.StyleNoFrame, Android.Resource.Style.Theme);
}
Hope it helps ;) 希望能帮助到你 ;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.