这是不可能的,但有一个使用Toolbar
. 现在您可以将其Toolbar
作为您的一部分包含在内,DialogFragment
layout xml
并且可以根据您的需要设置其设计/图标。setNavigationOnClickListener
如果您希望后退按钮的行为与正常情况一样,您还需要实现。请参阅下面的示例类。
package com.package.name;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MyDialogFragment extends DialogFragment {
private View parentView;
private Toolbar toolbar;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.Theme_AppCompat_NoActionBar);
return super.onCreateDialog(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//The layout xml file contains the toolbar
parentView = inflater.inflate(R.layout.dialogfragment_createpost, container, false);
initView();
initData();
return parentView;
}
private void initView() {
toolbar = (Toolbar) parentView.findViewById(R.id.toolbar);
}
private void initData() {
toolbar.setTitle("Post");
//Set naviagtion icon to back button drawable
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// handle back button naviagtion
dismiss();
}
});
}
}