6

この単純なダイアログを半透明にしようとしています:

class TestDialog extends SherlockDialogFragment
{


    public TestDialog()
    {
    super();        
    }




    @Override
    public Dialog onCreateDialog(Bundle savedInstanceStateBundle ) 
    {

    AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater1 = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder1.setView(inflater1.inflate(R.layout.dlg_test, null))
    // Add action buttons
    .setPositiveButton( "Ok", new DialogInterface.OnClickListener() 
     {

        @Override       
        public void onClick(DialogInterface dialog, int id)         
        {           
            // sign in the user ...                    
        }


     })
     .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() 
      {      
                 @Override
         public void onClick(DialogInterface dialog, int id)             
         {           

         }           
      });

        return builder1.create();

    }        


}

レイアウトは次のとおりです。

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

    <TextView
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="4dp"
        android:hint="User name" />

 </LinearLayout>

透明な .png を線形レイアウトの背景ドローアブルとして使用することから、アルファ フィールドを 0.5 に設定すること、ドローアブルとして 0 に等しい色を使用することまで、すべてを試しました。そのダイアログを半透明にすることはできません。 . それが可能かどうかさえわかりません。作成したいのは、次の画像のパネルのようなダイアログです半透明のコントロール パネル。ありがとう。注 1: 必要な最小 SDK はバージョン 8 で、ターゲットは最新 (実際には v17) です。

4

6 に答える 6

5

それ以外の:

return builder1.create();

これを入れてみてください:

Dialog dialog = builder1.create();
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
dialog.getWindow().setBackgroundDrawable(d);
return dialog;
于 2013-07-07T19:14:51.793 に答える
0

ダイアログ フラグメント参照で、これら 2 つのテーマのいずれかを試すことができます。

yourdialogFragment.setStyle(style,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

また

yourdialogFragment.setStyle(style,android.R.style.Theme_Holo_Light_Dialog);

これが役立つことを願っています。

于 2013-07-07T23:19:32.440 に答える