是否有可能在android中创建自定义对话框/卡,我不是很确定它叫什么,所以我还没有找到一些有用的东西。我想创建一些类似于
并在按下按钮时从我的主要活动中打开它,欢迎任何指导或帮助!
编辑:
抱歉,我认为我的问题以错误的方式出现了,我想要一个自定义对话框/卡片,例如像普通对话框一样显示为弹出窗口;
我已经尝试创建一个在android中预构建的普通默认对话框但是,这不适合我的应用程序的需要。
var excel = new LinqToExcel.ExcelQueryFactory(InputFileName);
var EData1 = (from c in excel.WorksheetRangeNoHeader("A1","IU100000", InputFileWorkSheet) select c).ToList<LinqToExcel.RowNoHeader>();
var EData2 = (from c in excel.WorksheetRangeNoHeader("IV1","ZZ100000", InputFileWorkSheet) select c).ToList<LinqToExcel.RowNoHeader>();
var ExcelData = new List<LinqToExcel.RowNoHeader>();
for (var i = 0; i < EData1.Count; i++)
{
var RowWithoutHeader = EData1[i].Concat(EData2[i]);
ExcelData.Add(new LinqToExcel.RowNoHeader(RowWithoutHeader));
}
答案 0 :(得分:0)
// add button listener
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
答案 1 :(得分:0)
您只需创建一个Fragment
扩展DialogFragment
。
要开始Fragment
,您需要处理FragmentManager
。
下面的代码显示了如何使用支持库开始使用Fragments。
getSupportFragmentManager().beginTransaction().add().commit();
在您的片段中,您可以根据需要自定义布局。
如果您只想轻松使用Dialogs,我建议您查看此库:
使用此功能,您只需使用类似以下代码创建对话框:
new MaterialDialog.Builder(this)
.title(R.string.title)
.items(R.array.items)
.itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
/**
* If you use alwaysCallSingleChoiceCallback(), which is discussed below,
* returning false here won't allow the newly selected radio button to actually be selected.
**/
return true;
}
})
.positiveText(R.string.choose)
.show();
答案 2 :(得分:0)
在您的活动中创建静态内部类:
public static class MyDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.custom_dialog_view, container, false);
// Get your dialog views here ie.
TextView textView = v.findViewById(R.id.dialog_textview);
textView.setText("Im am dialog");
return v;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
public void onResume(){
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
}
在活动中创建如下对话框:
void showDialog() {
DialogFragment newFragment = new MyDialogFragment();
newFragment.show(getFragmentManager(), "dialog");
}
让您在xml中创建自定义视图
<强> custom_dialog_view.xml 强>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialog_textview" />
</LinearLayout>