【发布时间】:2013-07-07 18:47:53
【问题描述】:
我正在尝试使这个简单的对话框半透明:
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 作为线性布局的背景可绘制对象,到将 alpha 字段设置为 0.5,再到使用等于 0 的颜色作为可绘制对象。我无法制作该对话框半透明。我不知道是否有可能。 我想要创建的是一个类似于下图中面板的对话框:。 谢谢。 注1:需要的min sdk是8,target是最新的(其实是v17)。
【问题讨论】:
-
我认为这可能取决于 SDK 版本。在 1.6 中,默认情况下对话框是半透明的,但请尝试
AlertDialog.Builder(Context context, int theme),其中主题是 `android.R.style.Theme_Dialog。 -
您是否尝试过在 XML 中使用类似
android:background="#4000"的内容? (#4000 是 ARGB_4444 颜色空间)。 -
我都试过了,但都没用。
标签: android actionbarsherlock android-dialogfragment