注意:我尝试使用对话框和alertdialog
两者。
示例:this我已经尝试过了。
代码:
private Dialog mDialog;
public void showCategoryDialog() {
LayoutInflater li = LayoutInflater.from(context);
promptsView = li.inflate(R.layout.row_category_dialog_layout, null);
findViewById();
init();
setClickListener();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context, R.style.dialogBoxStyle);
alertDialogBuilder.setView(promptsView);
alertDialogBuilder.setPositiveButton(context.getString(R.string.new_category), null);
alertDialogBuilder.setNegativeButton(context.getString(R.string.cancel), null);
recyclerView();
search();
mDialog = alertDialogBuilder.create();
mDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
Button buttonNegative = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isEditPayment = false;
showDialogBox(0);
}
});
buttonNegative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
mDialog.show();
}
答案 0 :(得分:0)
如果您想使用AlertDialog
白色透明窗口,则可以从DialogFragment
使用并设置:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.NewDialog);
}
styles.xml中的NewDialog:
<style name="NewDialog" parent="@android:style/Theme.Dialog">
<item name="android:textColor">@color/dark</item>
<item name="android:colorBackground">@color/lighgray2</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:textSize">13dp</item>
<item name="android:textStyle">bold</item>
<item name="android:minWidth">250dp</item>
<item name="android:textAlignment">center</item>
<item name="android:height">20dp</item>
</style>
还可以在DialogFragment
中设置自定义布局,使其在透明窗口中显示所需内容。
更完整的示例:
public class TVShowFragment extends DialogFragment {
RecyclerView rv;
TellListAdaptor adapter;
List<TellListModel> tellListModels = new ArrayList<>();
public static String CustomerName;
public static boolean isCustomer;
private TellListModel tellListModel;
int newMsgPosition;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.your_custom_layout, container);
//RECYCER
rv = rootView.findViewById(R.id.mRecyerID);
rv.setLayoutManager(new LinearLayoutManager(this.getActivity()));
//ADAPTER
adapter = new TellListAdaptor(tellListModels);
rv.setAdapter(adapter);
if (FragmentRoute.OperatorPhons.size() != 0) {
for (int i = 0; i < FragmentRoute.OperatorPhons.size(); i++) {
tellListModel = new TellListModel(FragmentRoute.OperatorPhons.get(i), CustomerName);
tellListModels.add(tellListModel);
newMsgPosition = tellListModels.size() - 1;
adapter.notifyItemInserted(newMsgPosition);
adapter.notifyDataSetChanged();
}
}
}
this.getDialog().setTitle( CustomerName);
TextView textView = getDialog().findViewById(android.R.id.title);
textView.setTextSize(15);
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
textView.setGravity(Gravity.CENTER);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.NewDialog);
}
}
称之为:
final TVShowFragment tv = new TVShowFragment();
tv.show(MainActivity.fm, "TV_tag");