1

I'm making a Activity Dialog and want to customize the layout of the Activity. I already had set in the manifest the custom style by my activity which extends "@android:style/Theme.Holo.Dialog".

If I use <item name="android:windowTitleStyle">CUSTOM_STYLE_NAME</item> the only change of backgroundcolor is behind the title and not the whole actionbar.

Setting <item name="android:actionBarStyle"> in my custom style didn't help either.

So how can I change the background of my actionbar in my Activity Dialog?

enter image description here

Carlo Matulessy
  • 975
  • 1
  • 13
  • 27
  • apply a dialog theme to activity and use it like a dialog – Raghunandan Dec 11 '13 at 10:55
  • Possible duplicate of http://stackoverflow.com/questions/9302449/android-change-custom-dialog-title-background – Triode Dec 11 '13 at 10:58
  • Hi Raghunandan thanks for the response, but the problem is that I have a dialog theme with an actionbar, and if I style the windowTitleStyle, only the background of the text will be get the color and not the whole titlebar/actionbar – Carlo Matulessy Dec 11 '13 at 10:58

2 Answers2

1

I have fixed with this tweak I found on stackoverflow. What you basically do is to declare your own dialog style which you add to your activity as theme:

<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>

Than declare in your oncreate the follow method:

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);
}

After this you can add your own custom actionbar style with the background color of your choice:

<item name="android:actionBarStyle">@style/MyActionBar</item>

ps. LayoutParams is from WindowManager

Community
  • 1
  • 1
Carlo Matulessy
  • 975
  • 1
  • 13
  • 27
0

I didn't see your custom style XML so, I guess you set textbackground instead of backgrondcolor..

EsmaeelQash
  • 488
  • 2
  • 6
  • 20