【发布时间】:2016-05-23 18:33:27
【问题描述】:
getActionBar().hide();将崩溃导致 getActionBar 为空。 这也不起作用:
<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
这是我的代码:
public static void popupWindow(final Context context,String title ,String desc,final CrudStateCallback back){
final Dialog dialog = new Dialog(context, R.style.ShowPopup);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
dialog.setContentView(R.layout.sticky_layout);
colourTitleBar(context, dialog);
String sansproEL = "fonts/source_sans_pro_extraLight.ttf";
String sansproL = "fonts/source_sans_pro_light.ttf";
Typeface sansproL_TF = Typeface.createFromAsset(context.getAssets(), sansproL);
Typeface sansproEL_TF = Typeface.createFromAsset(context.getAssets(), sansproEL);
((TextView)dialog.findViewById(R.id.popup_text)).setTypeface(sansproL_TF);
((TextView)dialog.findViewById(R.id.popup_text2)).setTypeface(sansproEL_TF);
TextView text = (TextView) dialog.findViewById(R.id.popup_text);
TextView text2 = (TextView) dialog.findViewById(R.id.popup_text2);
RelativeLayout container = (RelativeLayout) dialog.findViewById(R.id.all_container);
View.OnClickListener dismissList = new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
if(back!= null)
back.onResponse("");
}
};
text.setText(title);
text2.setText(desc);
container.setOnClickListener(dismissList);
PSLocationCenter.getInstance().instabug.setDialog(dialog);
dialog.show();
Handler han = new Handler();
han.postDelayed(new Runnable() {
@Override
public void run() {
try{
dialog.dismiss();
}catch (Exception e){
Log.i("","error in popup window");
}
if(back!= null)
back.onResponse("");
}
}, 3000);
}
public static void colourTitleBar(Context context, Dialog dialog) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
dialog.getWindow().setStatusBarColor(context.getResources().getColor(android.R.color.transparent));
}
}
还有我的风格:
<style name="ShowPopup">
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/ShowPopupAnimation</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
【问题讨论】:
标签: android dialog android-actionbar styles