0

私はAndroidアプリケーションで作業しています。ここではカスタムダイアログボックスを作成しました。このダイアログボックスはデバイスの高さ全体に表示されていましたが、下のコードを使用してマージンを設定しました。警告ダイアログボックスから黒い背景を削除 - Android

WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
    lp.copyFrom(alertDialog.getWindow().getAttributes()); 
    lp.width = WindowManager.LayoutParams.WRAP_CONTENT; 
    lp.height = Utility.convertDPtoPixel(400, screen); 

    alertDialog.show(); 
    alertDialog.getWindow().setAttributes(lp); 

上記のコードは完全に機能しましたが、ダイアログは黒い背景で表示されます。今私は、ダイアログボックスからこれらの黒周囲を削除したい

Screen shot with black surroundings

:ここ

は、スクリーンショットです。

ここ

は、ダイアログボックスのコードです:

public void showDialog() { 
    AlertDialog.Builder builder; 
    final AlertDialog alertDialog; 
    //final Dialog alertDialog; 
    Context mContext; 
    mContext = screen; 
    LayoutInflater inflater = (LayoutInflater) LoginActivity.screen.getSystemService(LoginActivity.screen.LAYOUT_INFLATER_SERVICE); 
    layout = inflater.inflate(R.layout.countrylist, null); 
    LinearLayout rellayout = (LinearLayout) layout.findViewById(R.id.rellayout); 

    RelativeLayout closeAcessCodeDialog = (RelativeLayout)layout.findViewById(R.id.closeAcessCodeDialog) ; 

    ListView listview = (ListView) layout.findViewById(R.id.listview); 
    listview.setAdapter(new CustomAdapter1(LoginActivity.screen, countryList)); 

    builder = new AlertDialog.Builder(LoginActivity.screen); 
    builder.setView(layout); 
    alertDialog = builder.create(); 
    alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
    lp.copyFrom(alertDialog.getWindow().getAttributes()); 
    lp.width = WindowManager.LayoutParams.WRAP_CONTENT; 
    lp.height = Utility.convertDPtoPixel(400, screen); 

    alertDialog.show(); 
    alertDialog.getWindow().setAttributes(lp); 


    listview.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int pos, 
           long id) { 
      countryName = idCountry.get(pos); 
      System.out.println("Country code is: " + countryName); 
      alertDialog.cancel(); 
      text.setText(countryList.get(pos)); 
     } 
    }); 

    closeAcessCodeDialog.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      alertDialog.dismiss(); 
     } 
    }); 

} 

countrylist.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardBackgroundColor="#ffe264" 
    app:cardCornerRadius="10dp" 
    > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/rellayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:layout_above="@+id/listview" 
      android:gravity="center_vertical" 
      > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Select your Country" 
       android:textColor="#000" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:layout_centerInParent="true" 
       /> 

      <RelativeLayout 
       android:id="@+id/closeAcessCodeDialog" 
       android:layout_width="60dp" 
       android:layout_height="60dp" 
       android:layout_alignParentRight="true" 
       android:gravity="center"> 

       <ImageButton 
        android:id="@+id/closeDialog" 
        android:layout_width="30dp" 
        android:layout_height="30dp" 
        android:background="@drawable/close_country_dialog" /> 

      </RelativeLayout> 
     </RelativeLayout> 


     <ListView 
      android:id="@+id/listview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:cacheColorHint="@android:color/transparent" 
      android:divider="#e5e5e5" 
      android:background="@drawable/list_bacground" 
      android:dividerHeight="1px" /> 

    </LinearLayout> 

私はstackoverflowのに比べて多くの似たリンクを訪問しましたが、誰が参考になっありませんでした。

+0

androidmanifestのTheme.Translucent.NoTitleBarでアクティビティテーマを変更してください。 –

+0

テーマが機能しない場合は、setBackgroundDrawableResourceを に変更してください。alertDialog.getWindow()。setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); これがあなたを助けてくれることを願っています。 –

+0

@AndyDeveloperテーマで試しましたが、うまくいきません。 –

答えて

2

あなたのAlertDialogそれはあなたがカスタム使うべきimport android.support.v7.app.AlertDialog;ともう一つあるべきの輸入をチェックする必要がありますので、これは多くの

あなたを助けることを願っていますが、私は黒人である、デフォルトのテーマカラーを考えます以下のような背景の色

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
+0

show()メソッドが機能した直後に、パッケージを変更してalertDialog.getWindow()。setBackgroundDrawable()を設定すると、素晴らしいMan! –

+0

こんにちは、あなたが気にしないなら、私の質問をupvoteできますか?それは関連する質問であり、答えを出すのに十分な情報を持っているので、しかし誰かがそれをdownvotedしました。 –

+0

確かに....でも、あなたは私の答えと同じようにしなければなりません。 –

0

これを試してみてください。

Dialog alertDialog = new Dialog(this); 
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
alertDialog.setContentView(R.layout.yourlayout); 
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
alertDialog.show(); 
関連する問題