Android : Queries regarding actionbar

on Sunday, August 17, 2014


I am trying to add background colour to my action bar..My manifest has fllowing activity declaration-



<activity
android:name=".ui.LeagueSelect"
android:label="INDIAN SPORTS LEAGUES"
android:theme="@style/MyTheme2"></activity>


and my styles.xml has



<style name="MyTheme2" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar2</item>


</style>
<style name="MyActionBar2" parent="@style/Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:background">#12ABEE</item>
<item name="android:actionMenuTextColor">#ffffff</item>
<item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>


When I run this code no action bar appears.I tried changing android:windowFullscreen=fallse but still same output..If i change the theme it crashes at running displaying error " You need to use a Theme.AppCompat theme (or descendant) with this activity."..


Here is my another class declararion in manifest-



<activity
android:name=".ui.slidingmenu.Home"
android:label="@string/app_name"
android:theme="@style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


ans styles.xml



<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabStyle">@style/MyTheme.ActionBar.TabView</item>
<item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:background">#12ABEE</item>
<item name="android:gravity">center</item>
<item name="android:actionMenuTextColor">#ffffff</item>
<item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>
<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
<item name="android:textColor">#ffffff</item>
<item name="android:textStyle">bold</item>
<item name="android:gravity">center</item>

</style>


Here actionbar is displayed with the required background colour(#12ABEE) but the title is not centre aligned..i have put android:gravity=center still title is left aligned..


0 comments:

Post a Comment