我正在尝试实现flipkart 应用程序的操作栏功能。
.
为此,我已成功创建了一个自定义操作栏,但我在将菜单显示为溢出图标单击下拉菜单时遇到了问题。
如果我尝试在按钮上单击 Android 选项菜单,然后在我的屏幕底部中心获得没有图标的菜单 (4.2.2)。使用自定义对话框或警报对话框会淡化背景,它们也会出现在屏幕中央。
我应该怎么做才能获得与上图类似的功能?
android optionmenu android-alertdialog android-dialog android-styles
在实现新的Android M权限模型时,我注意到权限对话框不尊重styles.xml的主题.
在我的styles.xml中,我覆盖了对话框和alertdialog样式,如下所示:
<item name="android:dialogTheme">@style/Theme.dialog</item>
<item name="android:alertDialogTheme">@style/Theme.dialog</item>
Run Code Online (Sandbox Code Playgroud)
是否有可能改变主题?
或者是因为这是设备设置中的系统对话框?
android android-dialog android-permissions android-6.0-marshmallow
我有一个包含项目列表的对话框片段。默认情况下,当您触摸某个项目时,对话框会关闭。此时如何防止解雇?(我想在稍后阶段以编程方式关闭对话框)
我正在按照此处的指示关注代码示例:https : //developer.android.com/guide/topics/ui/dialogs.html
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.pick_color)
.setItems(R.array.colors_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
Run Code Online (Sandbox Code Playgroud)
我看到有一个选项可以使用builder.setSingleChoiceItems而不是builder.setItems(),这会给我我想要的行为,但不是风格。(它带有单选按钮,我不想要)
我已经显示AlertDialog了 2 个按钮,即是和取消,这是代码。
final AlertDialog.Builder builder = new AlertDialog.Builder(RiderDetailActivity.this);
builder.setCancelable(false);
builder.setMessage("Are you sure?");
final AlertDialog dialog = builder.create();
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
dialog.show();
Run Code Online (Sandbox Code Playgroud)
这仅在三星 Galaxy s4 上不显示是和取消按钮
但是当我将它与它一起使用dialog.setButton时效果很好
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override …Run Code Online (Sandbox Code Playgroud) 在 Chintan Khetiya 的这个答案的帮助下,我创建了一个自定义的底部表单 android 对话框:How to create a Custom Dialog box in android? .
我想从BottomDialogue 自己的Activity.Not from Calling 活动中定义的按钮关闭对话框。
这是我在 Calling 活动中的代码,其中我通过单击按钮创建了我的自定义 BottomSheet_liab 实例:
openBottomDialogeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
**//Creating the BottomDialogue Instance**`Bottomsheet_liab dialog;
dialog=new Bottomsheet_liab(getActivity());
dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));`
}
});
Run Code Online (Sandbox Code Playgroud)
这是我在对话活动中的代码:
public class Bottomsheet_liab extends BottomSheetDialog{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cashflow_bottomsheet);
Button btn=(Button)findViewByID(R.id.btnx);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
**//I want to dismiss this BottomSheetDialogue from here.How can I …Run Code Online (Sandbox Code Playgroud) 我suspendCoroutine用来避免在Dialogs 中使用回调。但是,在 Android 中Dialog,Continuation.resume()当对话框关闭时(通过在对话框区域外单击),没有明显的调用位置。如果您尝试调用,Dialog.setOnDismissListener()则必须跟踪是否已经在按钮侦听器中调用了 resume。
suspend fun displayDialog() = suspendCoroutine<String?> { continuation ->
val builder = AlertDialog.Builder(context)
builder.setCancelable(true)
builder.setNegativeButton(android.R.string.cancel) { _, _ ->
continuation.resume(null)
}
builder.setPositiveButton(android.R.string.ok) { _, _ ->
continuation.resume("it's ok")
}
val dialog = builder.show()
dialog.setOnDismissListener {
// if the user clicked on OK, then resume has already been called
// and we get an IllegalStateException
continuation.resume(null)
}
}
Run Code Online (Sandbox Code Playgroud)
那么,最好跟踪是否已经调用了 resume(以避免第二次调用它),或者只是不打扰resume(null)调用(在 onDismissListener 中)?
我正在尝试为 DialogFragment 创建一个独立的单元测试,以便 DialogFragment 可以单独进行测试。我正在使用 FragmentScenario 启动 DialogFragment,现在我正在尝试确认是否显示对话框消息,但最终我将测试按钮单击。
class ResetScoreDialog (val viewModel: MyViewModel) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
// Use the Builder class for convenient dialog construction
val builder = AlertDialog.Builder(it)
builder.setMessage(getString(R.string.resetscore_dialog_message))
.setPositiveButton(getString(R.string.confirm),
DialogInterface.OnClickListener { dialog, id ->
viewModel.resetScore()
})
// Create the AlertDialog object and return it
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试
@RunWith(RobolectricTestRunner::class)
class ResetScoreDialogTest {
private lateinit var scenario: FragmentScenario<ResetScoreDialog>
private lateinit var viewModel: MyViewModel …Run Code Online (Sandbox Code Playgroud) android android-dialog android-dialogfragment android-espresso
当用户执行某些操作(例如注册)时,我想显示不确定的进度对话框。使用ProgressDialog.
对于 compose,我发现了这个How can I render plain android ProgressBar with Compose?但这并不是我想要的,因为它只是一个视图。它不像对话框那样覆盖屏幕。
随着CircularProgressIndicator我能够做到这一点:
如您所见,它显示在视图下方。
我想创建这样的东西:
它应该有:
如何在 Jetpack compose 中实现这一点?
我的简单代码在Android中显示了一个Dialog.当用户在对话框外部单击或对话框失去焦点时,我不想隐藏对话框.我该怎么做?
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
Toast.makeText(getApplicationContext(), "yes", Toast.LENGTH_LONG).show();
break;
case DialogInterface.BUTTON_NEGATIVE:
Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_LONG).show();
break;
}
}
};
Run Code Online (Sandbox Code Playgroud)
按钮代码是:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?")
.setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
Run Code Online (Sandbox Code Playgroud)
谢谢.
请帮我用NumberPicker从https://github.com/SimonVT/android-numberpicker.我有片段里面有我的按钮.单击按钮后,我想显示我的号码选择器(作为弹出窗口,而不是新屏幕).所以我做了什么:我创造了NumberPickerCustomDialog
public class NumberPickerCustomDialog extends DialogFragment {
Context context;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// get context
context = getActivity().getApplicationContext();
// make dialog object
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// get the layout inflater
LayoutInflater li = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate our custom layout for the dialog to a View
View view = li.inflate(R.layout.activity_dark, null);
// inform the dialog it has a custom View
builder.setView(view);
// and if you need to call some …Run Code Online (Sandbox Code Playgroud) android android-fragments android-dialog android-dialogfragment