この単純なダイアログフラグメントが半透明にする方法:私はこの単純なダイアログ半透明にしようとしています
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に設定すること、drawableとして0に等しい色を使用することに、私はそのダイアログを半透明にすることはできません。私はそれが可能であってもわからない。 私が作成したいのは、次の画像のパネルのようなダイアログです:。おかげさまで 注1:必要な最小sdkはバージョン8で、ターゲットは最新(実際はv17)です。
:その後、
としてダイアログを作成します:関連する質問に対する私の答えに
リンクカスタムスタイルを作成し
SDKのバージョン。 1.6のダイアログでは、デフォルトで半透明ですが、テーマが 'android.R.style.Theme_Dialog 'の場合、' AlertDialog.Builder(Context context、int theme) 'を試してください。 – techiServices
XMLで 'android:background ="#4000 "'のようなものを使ってみましたか? (#4000はARGB_4444色空間です)。 – techiServices
私は両方を試しましたが、うまくいきませんでした。 –