2016-09-04 3 views
2

Ich kann den Hintergrund nicht transparent auf API 19 setzen, stattdessen bekomme ich einen weißen Hintergrund. Der Hintergrund ist nur für API 21 und höher transparent.Hintergrund nicht transparent auf API 19

Ich habe eine Aktivität, die ein benutzerdefiniertes Dialogfeldfragment aufruft. Das übergeordnete Layout des Dialogfragments hat background="@android:color/transparent".

Was mache ich falsch? Fehle ich etwas? Irgendwelche Hinweise wären wirklich hilfreich.

Lösungen, die ich versucht habe:

background="@null"

Dialog with transparent background in 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/

auf MyActivityTheme

Eltern Layout transparent Grundfarbe ändern 91.363.210

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

<?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

<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> 
+0

Sie wollten den Hintergrund transparent für den Dialog? – Naz141

+0

Ja, das tue ich. Der Hintergrund ist nur für API 22 und höher transparent, aber nicht für API. 19 – PLOW

+0

Versuchen Sie es einfach mit Ihrem Code zu ersetzen. 'dialog.getWindow(). SetBackgroundDrawable (neue ColorDrawable (Color.TRANSPARENT));' – Naz141

Antwort

-1

Ich glaube, Sie müssen diesen Code in Ihre onResume hinzufügen() -Methode:

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); 
     } 

Hoffe es hilft;)

+0

das hat nicht geholfen. Ich fügte es hinzu und behielt alles andere gleich. – PLOW

Verwandte Themen