2016-06-21 13 views
-1

ich ein PopUp mit dem folgenden Code erstellt:erstellen PopUp mit Hintergrund dahinter 50% transparent

JAVA:

public class PopUp extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.activity_pop_up); 

     DisplayMetrics dm = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(dm); 

     int width = dm.widthPixels; 
     int height = dm.heightPixels; 

     getWindow().setLayout((int) (width * 0.6), (int) (height * 0.6)); 


} 

Stil XML

<style name="AppTheme.CustomTheme"> 
     <item name="android:windowIsTranslucent">true</item> 
     <item name="android:windowNoTitle">true</item> 
    </style> 

Nun, mein popUp ist gut, aber ich möchte einen Hintergrund halb transparent dahinter, nicht vollständig transparent wie es ist. Ich möchte etwas wie folgt aus:

Aktivität ohne popUp:

Activity without popUp

Aktivität mit popUp:

Activity with popUp

Kann mir jemand helfen? Danke.

+0

möglich [duplizieren] (http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android) - nur nicht-Alpha-Alpha-Kanal-Werte verwenden – kirinthos

Antwort

0
Dialog dialog = new Dialog(this, R.style.AppTheme_NoActionBar); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    ColorDrawable dialogColor = new ColorDrawable(Color.BLACK); 
    dialogColor.setAlpha(200); 
    dialog.getWindow().setBackgroundDrawable(dialogColor); 
    dialog.setContentView(R.layout.activity_result); 


    dialog.setCancelable(false); 
    dialog.setCanceledOnTouchOutside(false); 
    dialog.show(); 

und Alpha entsprechend einstellen.

Verwandte Themen