【问题标题】:How to remove the border frame a dialogframe如何删除边框框架一个对话框
【发布时间】:2013-06-11 13:45:29
【问题描述】:

据我所知,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>

这是 drawable

<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;
    }
}

【问题讨论】:

    标签: android


    【解决方案1】:

    我用过

    public class EventAgeGateDialogFragment extends DialogFragment implements DatePicker.OnDateChangedListener {
    
        @Override
        public void onResume()
        {
            super.onResume();       
            getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);
        }
    
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Dialog dialog = super.onCreateDialog(savedInstanceState);
            dialog.requestWindowFeature(DialogFragment.STYLE_NO_TITLE);
            View view = View.inflate(getActivity(), R.layout.the_dialog_layout, null);
            dialog.setContentView(view);  
            return dialog;
        }
    }
    

    【讨论】:

    • 但是在背景触摸时对话框片段不可关闭。如何解决此问题
    【解决方案2】:

    这行代码对你有帮助

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

    同时检查两个链接

    1. AlertDialog: How To Remove Black Borders Above and Below View
    2. DialogFragment remove black border

    【讨论】:

    • 试过这个:context.setTheme(R.style.DialogTheme);对话框对话框=新对话框(上下文); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));但结果边框相同
    • 也看到了那些帖子,但没有结果。
    猜你喜欢
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多