我有一个简单的DatePickerDialog打开时EditText打开.选择日期并按OK后,应显示相同的日期EditText.如果我只使用默认对话框,它只创建一个按钮就可以正常工作 - 好的.我添加了一个取消按钮,问题是它只获取当前日期.
这是我的代码:
private void showDatePicker(String birthdayStr) {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
if (birthdayStr.equals("")) {
yearStr = c.get(Calendar.YEAR);
monthStr = c.get(Calendar.MONTH);
dayStr = c.get(Calendar.DAY_OF_MONTH);
}
DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
if (isOkayClicked) {
birthday.setText(selectedYear + (selectedMonth + 1) + selectedDay);
yearStr = selectedYear;
monthStr …Run Code Online (Sandbox Code Playgroud) 突然(这个项目代码没有任何变化)我开始得到一个错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{<package>}: java.lang.IllegalArgumentException: Button does not exist
Run Code Online (Sandbox Code Playgroud)
该错误指向尚未调用的方法.
private void dialog(String title, String content){
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(content);
alertDialog.setCancelable(true);
alertDialog.setButton(1, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
我试图在其他项目中复制并使用该代码 - 结果相同,并且它不久前工作(相同的目标API等).知道我在忽视什么吗?
我有一个自定义对话框,其中有2个进度条和一个按钮.我在onPreExecute ()AsyncTask中显示这个对话框并onPostExecute()
解决它的问题是,当我在操作期间触摸屏时对话框消失.我希望它只在按下对话框上的取消按钮或下载文件完成时才解除.
我只需按照http://www.laurivan.com/make-dialogs-obey-your-material-theme/来设计我的alertdialog的材料设计风格.但是,我发现我仍然无法像这个网站一样,以下是我的代码和截图:
值-V14/styles.xml:
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:dialogTheme">@style/MyDialogTheme</item>
<item name="android:alertDialogTheme">@style/MyDialogTheme</item>
</style>
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@color/transparent</item> …Run Code Online (Sandbox Code Playgroud) 我想在一个自定义Dialog中显示 2 个选项卡Activity,但出现以下错误。
错误:
No view found for id 0x7f0f0134 (com.hiro.chatio:id/viewPage_theme) for fragment
PostColorPickerFragment{35ffefce #0 id=0x7f0f0134 android:switcher:2131689780:0}
java.lang.IllegalArgumentException: No view found for id 0x7f0f0134 (com.hiro.chatio:id/viewPage_theme)
for fragment PostColorPickerFragment{35ffefce #0 id=0x7f0f0134 android:switcher:2131689780:0}
Run Code Online (Sandbox Code Playgroud)
MainActivity:
private Button pick_color;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_blog);
pick_color = (Button) findViewById(R.id.create_blog_color_btn);
pick_color.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(CreateBlogActivity.this);
dialog.setContentView(R.layout.blog_theme_picker);
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().getAttributes().windowAnimations = R.style.SlideUpDialogAnimation;
Button pickColor = (Button) dialog.findViewById(R.id.pick_color_btn);
Button default_color …Run Code Online (Sandbox Code Playgroud) 在我的代码中,单击文本视图时,我必须打开另一个对话框片段,文本视图位于主对话框片段中
textView.setOnClickListener(new View.OnclickListener(){
@Override
public void onClick(View v){
NewDialogFragment.newInstance().show(getChildFragmentManager(),"");
dismiss();
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,当在主对话框片段中单击文本视图时,dismiss()但新的 DialogFragment 未打开,
预期的结果是主dialogFrament应该dismiss()出现NewDialogFragment()
谢谢
android android-fragments android-dialog android-dialogfragment android-studio
我对 Fragment 中的 RecyclerView 和Dialog.
myAdapter = MyAdapter();
var lm = LinearLayoutManager(this.context)
myRecyclerView.layoutManager = lm;
myRecyclerView.adapter = myAdapter;
var line = DividerItemDecoration(this.context, lm.orientation);
myRecyclerView.addItemDecoration(line);
Run Code Online (Sandbox Code Playgroud)
奇怪的是,分隔线显示在片段中,但未显示在对话框中。这是一个已知问题吗?还是我做错了什么?我只是想显示项目之间的内置黑线分隔线。
我在自定义对话框的构造函数中调用了上面的代码。
class MyDialogue:Dialog
{
constructor(context: Context?) : super(context)
{
setContentView(R.layout.my_dialogue);
window.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//That code above.
}
Run Code Online (Sandbox Code Playgroud)
补充:似乎默认行正在使用android.R.attr.listDivider. 我只是不明白为什么 RecyclerView 没有在对话框中得到它。作为一种解决方法,我手动将 drawable 设置为装饰器,现在我可以看到默认分隔符。代码如下。但我为什么要这样做呢?
val a = context!!.theme.obtainStyledAttributes(
R.style.AppTheme, intArrayOf(android.R.attr.listDivider));
val attributeResourceId = a.getResourceId(0, 0)
val drawable = context.getDrawable(attributeResourceId)
line.setDrawable(drawable);
a.recycle();
Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码使用 Jetpack Compose 制作全屏对话框:
Dialog(onDismissRequest = { /*TODO*/ }) {
NewPostDialog()
}
Run Code Online (Sandbox Code Playgroud)
它最终看起来像这样。如何去除侧面的边距(标记为红色)?

我正在尝试在单击某个EditText时引发DatePickerDialog.但是,每次单击EditText时,应用程序都会崩溃.这是相关代码和LogCat.
EditText及其OnClickListener:
addBirth.setClickable(true);
addBirth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
}
});
Run Code Online (Sandbox Code Playgroud)
onCreateDialog方法和DateSetListener:
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case DATE_DIALOG_ID:
DatePickerDialog dialog = new DatePickerDialog(getApplicationContext(), mDateSetListener, mYear, mMonth, mDay);
return dialog;
}
return null;
}
protected DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth; …Run Code Online (Sandbox Code Playgroud) 我有一个复选框对话框,我想通过deafult检查设置它的一些值.
我的复选框对话框如下:
final String[] layers_name=new String[3];
for (int i=0;i<m_Renderer.m_Project.m_Layers.size();i++)
{
layers_name[i]=m_Renderer.m_Project.m_Layers.get(i).m_LayerName;
}
this.m_listview=new AlertDialog.Builder(c);
m_listview.setTitle("Layers Information").setMultiChoiceItems(layers_name,null,new DialogInterface.OnMultiChoiceClickListener()
{
@Override
public void onClick(DialogInterface dialog,int which,boolean ischecked)
{
if (ischecked)
{}
else
{}
}
}
).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}
);
m_listview.show();
Run Code Online (Sandbox Code Playgroud)
我在这个对话框中有3个项目我希望每次打开此对话框时检查其中2个项目.