此問題已被解答爲Dialog
而我知道的不是DialogFrame
。如何刪除對話框中的邊框
我想刪除此圖片中顯示的邊框。 對不起,沒有圖片允許。
這是我的代碼:
public class SettingDialogFragment extends DialogFragment {
public SettingDialogFragment() {
// constructor
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), 0);
context.setTheme(R.style.dialog);
AlertDialog.Builder alertDlgBldr = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
alertDlgBldr.setView(inflater.inflate(R.layout.dialog_theme, null));
return alertDlgBldr.create();
}
}
這是佈局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/dialog_title"
style="@style/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/dialog_theme_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/logo_color"
android:textStyle="bold" />
<TextView
android:id="@+id/dialog_text"
style="@style/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/dialog_text"
android:layout_below="@id/dialog_title"
android:text="Demonstation how to use vector drawables to style a dialog box"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/logo_color" />
<ImageView
android:id="@+id/dialog_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@id/dialog_text"
android:layout_centerHorizontal="true"
android:src="@drawable/cats_dogs" />
</RelativeLayout>
這是風格
<style
name="dialog">
<!-- title encapsulating main part (backgroud) of custom alertdialog -->
<item
name="android:windowFrame">@null</item>
<!-- turn off any drawable used to draw a frame on the window -->
<item
name="android:windowBackground">@drawable/dialog_background</item>
<!-- turn off any drawable used to draw a frame on the window -->
<item
name="android:windowIsFloating">true</item>
<!-- float the window so it does not fill the screen -->
<item
name="android:windowNoTitle">true</item>
<!-- remove the title bar we make our own-->
<item
name="android:windowContentOverlay">@null</item>
<!-- remove the shadow from under the title bar -->
</style>
這個繪製
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#00000000"/>
<corners
android:radius="10dp"/>
<stroke
android:color="#FFF000"
android:width="3dp" />
</shape>
我想我現在已經試過了這本書的每一招。搜索了三天的Stackoverflow現在,但大多數答案都與Dialog
不是DialogFragment
有關。 請幫我出來
這段代碼解決了這個問題,最後!
public class SettingDialogFragment extends DialogFragment {
public SettingDialogFragment() {
// this empty constructor without any parameter is required by Android
// to in order to instantiate the fragment when it needs to do so.
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, android.R.style.Theme_Light_Panel);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return super.onCreateDialog(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_theme, container, false);
return view;
}
}
嘗試這樣做:\t \t context.setTheme(R.style.DialogTheme); \t \t Dialog dialog = new Dialog(context); \t \t dialog.getWindow()。setBackgroundDrawable(new ColorDrawable(0));但具有相同的結果邊框 – PageMaker
看過那些帖子,但沒有結果。 – PageMaker