问题描述
在我的Galaxy Tab 10.1的日历应用程序,创建一个新的事件时,对话框出现与完成,并取消按钮在标题栏/操作栏区域。
In the Calendar app on my Galaxy Tab 10.1, when creating a new event a dialog comes up with Done and Cancel buttons in the title bar/action bar area.
我想在我的应用程序来实现这一点。我已经尝试过使用 setHasOptionsMenu(真)
除了覆盖 onCreateOptionsMenu
在我的 DialogFragment
的子类,但我的行动项目不会出现。我也打过电话 getDialog()。getActionBar()
从内部 onCreateView
,但它总是返回空
。
I'd like to implement this in my app. I've tried using setHasOptionsMenu(true)
in addition to overriding onCreateOptionsMenu
in my DialogFragment
subclass, but my action items do not appear. I've also tried calling getDialog().getActionBar()
from within onCreateView
but it always returns null
.
我能得到这个工作,如果我启动活动
而不是显示一个对话框,但是占据了整个屏幕。有没有一种标准的方式使用,以做到这一点 DialogFragment
?
I am able to get this working if I start an Activity
rather than showing a dialog but that takes up the whole screen. Is there a standard way to do this using a DialogFragment
?
推荐答案
使用从谷歌组帖子我能够把它关闭造型的活动。你要修改的高度和宽度,以你的选择preferably一个动态的大小。然后设置你的任何动作条按钮喜欢
using the idea from a google group post I was able to pull it off styling an activity. you would want to modify the height and width to a "dynamic" size of your choice preferably. Then set whatever ActionBar buttons you would like
<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
-
public static void showAsPopup(Activity activity) {
//To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
LayoutParams params = activity.getWindow().getAttributes();
params.height = 850; //fixed height
params.width = 850; //fixed width
params.alpha = 1.0f;
params.dimAmount = 0.5f;
activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
setContentView(R.layout.activity_main);
}
这篇关于动作条在DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!