以下是我的FragmentActivity和DialogFragment。我嘗試創建一個自定義AlertDialog。我已經部分實現了這一點,如下圖所示。我怎樣才能擺脫我的自定義AlertDialog周圍的白色區域?在DialogFragment中創建完全自定義的AlertDialog
public class MainActivity extends FragmentActivity {
public int mStackLevel = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialog();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void showDialog(){
mStackLevel++;
FragmentTransaction ft = getSupportFragmentManager ().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag ("dialogg");
if(prev != null)
{
ft.remove(prev);
}
ft.addToBackStack(null);
DialogFragment df = AppWizard.newInstance(mStackLevel);
df.show(ft, "dialogg");
}
public void doPositiveClick() {
// Do stuff here.
showDialog();
}
public void doNegativeClick() {
// Do stuff here.
}
public static class AppWizard extends DialogFragment {
int mNum;
static AppWizard newInstance(int num){
AppWizard aw = new AppWizard();
Bundle args = new Bundle();
args.putInt("num", num);
aw.setArguments(args);
return aw;
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mNum = getArguments().getInt("num");
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("num");
LayoutInflater lo = getActivity().getLayoutInflater();
View view = lo.inflate(R.layout.fragment_dialog, null);
final CharSequence[] items = {"Bir daha gösterme!"};
final boolean[] _selections = null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view);
return builder.create();
}
}
這裏是我的alertdialog佈局XML fragment_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_dialog"
style="@style/AlertDialogCustom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center"
android:orientation="vertical"
android:background="@android:drawable/alert_dark_frame" >
<TextView
android:id="@+id/dialog_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLABLABLA"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/dialog_header2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLABLABLA2"
android:textColor="@android:color/black"
/>
<Button
android:id="@+id/dialog_button"
android:layout_width="125dp"
android:layout_height="50dp"
android:text="Click"
android:textColor="@android:color/background_dark"
android:textSize="8sp"
android:textStyle="bold|italic"
/>
</LinearLayout>
我已經嘗試過,但不會改變任何不幸的事情。我已將TAG更改爲「dialogg」,還是應將其保留爲TAG?它會拋出錯誤,因爲TAG不可見。我完全是新的 – mctuna
你可以刪除'Log'。它只顯示'LogCat'中的消息。你能解釋你想從對話框中刪除哪部分? – hardartcore
那些白色部分(背景)圍繞着我的黑色AlertDialog。 – mctuna