Java DialogFragment上的自定义样式

Java DialogFragment上的自定义样式,java,android,android-fragments,android-gui,Java,Android,Android Fragments,Android Gui,这里可能有重复,抱歉那样的话 我不知道如何在DialogFragment中添加自定义样式。现在我有一节课 public final class SelectFragment extends DialogFragment { 我从应用程序的不同部分调用它。例如,在我的“CreateInvoice”类中,如下所示: private void showFragment(int selectedIndex) { SelectFragment fragment = SelectFragment.

这里可能有重复,抱歉那样的话

我不知道如何在DialogFragment中添加自定义样式。现在我有一节课

public final class SelectFragment extends DialogFragment {
我从应用程序的不同部分调用它。例如,在我的“CreateInvoice”类中,如下所示:

private void showFragment(int selectedIndex) {
    SelectFragment fragment = SelectFragment.newInstance(selectedIndex, getOnOptionSelectListener());
    fragment.setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
    fragment.show(getActivity().getSupportFragmentManager(), "");
}
我想做的是将fragment.setStyle更改为自定义样式,例如使用我自己的配色方案作为边框、背景等的颜色。。如果有人能带我看一下,我会非常感激,因为这是我第一次处理碎片。:-)


谢谢

我的方法是只需为对话框编写自己的布局,然后在显示片段时加载它

 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        View v = inflater.inflate(R.layout.custom_dialog_layout, null, false);
        builder.setView(v)
        // Add action buttons
               .setPositiveButton(R.string.save_note, new DialogInterface.OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int id) {
                       // do stuff 
                   }
               })
               .setNegativeButton(R.string.note_cancel, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                           //do stuff
                   }
               });      
您应该搜索“自定义对话框片段”。您将得到答案:)