java - DialogFragment 上的自定义样式

标签 java android android-fragments android-gui

这里可能重复,抱歉...

我不知道如何将自定义样式添加到我的 DialogFragment。此刻我正在上课

public final class SelectFragment extends DialogFragment {

我从应用程序的不同部分调用它。例如,来 self 的“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 更改为自定义的,例如使用我自己的配色方案作为边框、背景等的颜色。如果有人能引导我完成它,我将不胜感激,因为这是我第一次使用 fragment 。 :-)

谢谢!

最佳答案

我的做法是简单地为对话框编写自己的布局,然后在显示 fragment 时加载它

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

关于java - DialogFragment 上的自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021786/

相关文章:

android - 无法启动 Appium session ,错误为 : Error: Parameter 'appPackage' is required for launching application

java - setBackgroundResource 不起作用

java - 容纳唯一编号的最小(尺寸)物体?

java - 如何使用 XML 风格的 MyBatis-SpringBoot-MySQL 执行正确的 SQL INSERT?

java - 在独立模式下组装hadoop时出现Maven错误

android - 通知未打开 Activity onClick

android - Android 模拟器上的低功耗蓝牙

java - 无法使用processBuilder执行linux命令

java - 如何在不同的 fragment 中更改不同样式的操作栏标题?

java - 我如何在类和使用它的 fragment 之间进行通信?