我有一个自定义AlertDialog风格,使AlertDialog框透明。 它工作正常,除了当我膨胀到期望的透明布局到警报对话窗口,它显示了一个黑色的背景。 我的目标是有一个完全透明的AlertDialog ,好像只有4个button是浮动的,而不是一个框架。 图像一是自定义对话框给我的,图像二是我想要的或者我想要的。 这是自定义Dialog的代码 <style name="CustomDialog" parent="android:Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTitleStyle">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:background">@android:color/transparent</item> </style> 这是我在我的onCreate() AlertDialog.Builder imageDialog = new AlertDialog.Builder(TimeLine.this, R.style.CustomDialog); inflater = getLayoutInflater(); View view=inflater.inflate(R.layout.tabs, null);![enter image description here][1] AlertDialog a = imageDialog.create(); a.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); a.setView(view, 0, 0, 0, 0); […]
我正在尝试在DialogFragment使用自定义视图创build一个AlertDialog 。 这个视图必须从xml中夸大。 在我的DialogFragment类中,我有: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle("Title") .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, null)) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null) .create(); } 我已经尝试其他通胀方法.setView()如: .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getView(), false)) 和 .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getTargetFragment().getView(), false)) 在显示此对话框的片段中设置目标片段之后。 所有这些尝试膨胀我的自定义视图结果在以下例外: E/AndroidRuntime(32352): android.util.AndroidRuntimeException: requestFeature() must be called before adding content E/AndroidRuntime(32352): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:214) E/AndroidRuntime(32352): at com.android.internal.app.AlertController.installContent(AlertController.java:248) E/AndroidRuntime(32352): at android.app.AlertDialog.onCreate(AlertDialog.java:314) E/AndroidRuntime(32352): at android.app.Dialog.dispatchOnCreate(Dialog.java:335) […]
是的,我知道有AlertDialog.Builder,但是我很震惊地知道在Android中显示对话有多困难(至less不是程序员友好的)。 我曾经是一个.NET开发人员,我想知道是否有任何与Android相当的以下内容? if (MessageBox.Show("Sure?", "", MessageBoxButtons.YesNo) == DialogResult.Yes){ // Do something… }
我正在尝试用python语言编写一个用于pipe理用户的网页的seleniumtesting。 在此页面中,有人可以为用户添加angular色,如果angular色添加时存在angular色,则会引发警报。 我不知道警报是否是一个JavaScript警报或网页的元素。 我想自动检查警报是否存在,因为检查列表中的angular色会浪费时间并且有巨大的负载。 我试过这个: browser = webdriver.Firefox() browser.get("url") browser.find_the_element_by_id("add_button").click() try: alert = browser.switch_to_alert() alert.accept() print "alert accepted" except: print "no alert" 但它没有工作,我得到了“UnexpectedAlertPresentException”。 我也试过这个: browser = webdriver.Firefox() browser.get("url") browser.find_the_element_by_id("add_button").click() s = set(browser.window_handles) s.remove(browser.current_window_handle) browser.switch_to_window(s.pop()) 但是我得到了同样的例外。 此外,我试图访问与萤火虫警报,以检查我是否可以访问其属性,但右键点击被禁用。 即使在其他语言中,我也需要一个解决scheme。 无论如何,我可以理解这个方法。 我将不胜感激任何帮助。
在AlertDialog的Android文档中 ,它给出了在AlertDialog中设置自定义视图的以下指令和示例: 如果你想显示一个更复杂的视图,请查看名为“body”的FrameLayout并添加你的视图: FrameLayout fl = (FrameLayout) findViewById(R.id.body); fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT)); 首先,很明显add()是一个拼写错误,意思是addView() 。 我对使用R.id.body的第一行感到困惑。 它似乎是AlertDialog的身体元素…但我不能只是在我的代码B / C中input,它会给编译错误。 R.id.body在哪里被定义或分配? 这是我的代码。 我试图在构build器上使用setView(findViewById(R.layout.whatever) ,但它不起作用,我假设是因为我没有手动膨胀它? AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title") .setCancelable(false) .setPositiveButton("Go", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { EditText textBox = (EditText) findViewById(R.id.textbox); doStuff(); } }); FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an […]