ViewPageIndicator- Jake Wharton- Why tabs with viewpager shows title unlike ICS? - android

I am attaching image to explain my question in more detail.
Also attaching android manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="XXXXXXXXXX"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:targetSdkVersion="15" android:minSdkVersion="8"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:hardwareAccelerated="true">
<activity
android:label="#string/app_name"
android:name="TabsMainActivity"
<!-- If I remove the line below I get normal
ICS action bar instead of title bar u see in below image -->
android:theme="#style/Theme.PageIndicatorDefaults">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Also if you see the edit text and spinner UI , its like one that we see on android versions below ICS.
And Screenshot is from my phone running ICS 4.0.4.

I solved the problem by editing vpi__styles.xml from ViewPagerIndicator.
The code before I edited was : -
<style name="Theme.PageIndicatorDefaults" parent="android.Theme">
<item name="vpiCirclePageIndicatorStyle">#style/Widget.CirclePageIndicator</item>
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
The code after I edited file is :-
<style name="Theme"></style> <!-- I declared new style which dont have parent with android.Theme -->
<style name="Theme.PageIndicatorDefaults" parent="Theme"> <!-- Extended this style from style I declared above -->
<item name="vpiCirclePageIndicatorStyle">#style/Widget.CirclePageIndicator</item>
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
This solved the problem and shows action bar instead of title bar on android 4 devices and normal title bar on android 2.1- 2.3.x devices.

Related

Unable to give style to action bar in android studio 1.0.1

I am trying to give colour/image as background to the action bar in android studio (), max sdk ver 21, but with no success. What is wrong with the below code and or else how to do it:
<resources>
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:background">#drawable/back</item>
</style>
</resources>
If you are facing problem in android lollipop actionbar, then first of all you have to different style.xml file in your res folder named as values-v21.
in this create style.xml as in values folder.
you did not added parent theme correctly. you should create style1 whose parent is style2. In style2 parent add desired theme like parent="#android:style/ThemeOverlay.Material.Light".
In menifest add style1 as your application theme.
Take a look on example.
Here colorPrimary for your action bar,
colorPrimaryDark for your notification bar outside application,
colorAccent for native dialogs like progressbar, tabs etc.
<resources>
<style name="AppBaseTheme" parent="#android:style/ThemeOverlay.Material.Light">
<item name="android:colorPrimary">#color/material_blue_500</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/material_blue_700</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/material_green_A200</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
your xml file should be like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.slidingmenu"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="info.androidhive.slidingmenu.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If you haven't already, remember to reference your theme in AndroidManifest.xml:
android:theme="#style/CustomActionBarTheme"
Also, make sure that in your Java code, you activity extends ActionBarActivity instead of just Activity as you are using the AppCompat Support Library.
If none of this works, go to your build.gradle and check that in the dependencies section, you have:
compile 'com.android.support:appcompat-v7:21.0.3'

Holo theme in android makes application stop 'unfortunately'

so I'm trying to style my application, and I've run into problems when using the Holo theme. I have no intrest in earlier versions of android, so I'don't want to use AppCompat.
To do my error checking I have created an empty app with one blank activity. This is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/AppTheme_ActionBarTheme</item>
</style>
<style name="AppTheme_ActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/light_green</item>
<item name="android:titleTextStyle">#style/AppTheme_ActionBarTheme_Text</item>
</style>
<style name="AppTheme_ActionBarTheme_Text" parent="AppTheme_ActionBarTheme">
<item name="android:textColor">#color/light</item>
</style>
</resources>
and this is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fokamb.chmielowskim.fokamb" >
<uses-sdk android:targetSdkVersion="15" android:minSdkVersion="14"/>
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="#string/main_act_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I didn't change any other files, and I tried running this app on an emulator with API level 21 and my phone with api 19. On both, i get the message "Unfortunately, FokaMB has stopped"
Even though, in the preview window in android studio the app looks the way I would've liked it to.
So, where might be my mistake? If I use AppCompat app works fine, but im unable to change the text color of actionbar (even though the background changes). Any help would be greatly appreciated:)

Styling Android Action Bar

I've a newly created project and the first thing I want to do is add and style an action bar. I made it the way they tell in their official tutorials and even tried some other ways but I just can't make it work.
After many tries, I decided to do something really basic but even like that I can't make it work.
This is what I have:
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/blue</item>
</style>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Another question is what is the difference between the #android:style/Theme.Holo, #style/Theme.AppCompat.Light.DarkActionBar or simply Theme.AppCompat.Light.DarkActionBar?
Thanks.
Per the Using the Material Theme training, the Material theme (and AppCompat theme's which backport / use Material theming) use colorPrimary to color the action bar. Therefore your theme can be:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue</item>
</style>
You'll find more details on how to theme using AppCompat / Material in the AppCompat v21 blog post and in this pro-tip
I recommend you use this tools to generate ActionBar styles:
http://jgilfelt.github.io/android-actionbarstylegenerator/
Good Luck!

Generated style not being applied on Android application

I've used the following style:
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=zhc_style&compat=appcompat&theme=light_dark&actionbarstyle=solid&texture=1&hairline=1&neutralPressed=1&backColor=cd0079%2C100&secondaryColor=cd0079%2C100&tabColor=cd0079%2C100&tertiaryColor=303030%2C100&accentColor=cd0079%2C100&cabBackColor=002E3E%2C100&cabHighlightColor=cd0079%2C100
Long story short, it makes the ActionBar purple.
I've taken all the files from the .zip file and placed them in my project. Within the <resources> of the file styles_zhc_style.xml I've got:
<style name="Theme.Zhc_style" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_zhc_style</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Zhc_style</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Zhc_style</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Zhc_style</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Zhc_style</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Zhc_style</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_zhc_style</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_zhc_style</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Zhc_style</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.Zhc_style.Widget</item>
</style>
I've changed my Android Manifest to the following:
<application
android:allowBackup="true"
android:name="com.zhc.android.ZHCApp"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Zhc_style" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My minimum sdk version is 16, my target sdk version is 21.
I still get the dark ActionBar on top of my application. When I change the settings using the Style Generator to have the Base Theme 'Light' and move all the files again, I see that the ActionBar indeed becomes light themed. Lighter ActionBar, black instead of white letters... but still no purple.
What am I doing wrong?
I've 'solved' the problem by removing the NavigationDrawer Fragment I've used, and placed a Toolbar on top instead. (Android 5.0).
Not really a solution, but an alternative people could consider.

How to set label for app, but empty for all activities?

short and simple question:
I use the actionBarSherlock library, and wish to have only the app's label set to some string, yet all activities have the empty label unless specified otherwise.
I know you can go over each activity and set its label to "" , but is there a better solution? like using the styles ? I've tried putting :
<item name="android:label"></item>
in there, but it didn't do anything.
EDIT: fact is, for some reason, setting the label of all activities to "" , actually also change the label of the app on some android versions (tested on galaxy s mini, with android 2.3) , so its name is "" too. How come? is it a bug?
This is a bug on either android or any launcher i've tested on.
it seems that setting the label to the activities to "" (or at least the main one) sets the name of the app to "" , so the label of the application tag is just for the default value of all of its activities.
You can remove the whole title bar by putting <item name="android:windowNoTitle">true</item> in your app theme. I don't think you should have a title bar without a title (unless on devices running 3.0 or higher, where the title bar becomes the ActionBar and has more functionality), as it'll just waste valuable space.
If you are developing on 3.0+, as well as 2.3, add the following elements to your theme:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
EDIT:
styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- Base Theme style elements -->
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Other style elements. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="AppThemeWithTitle" parent="AppTheme">
<item name="android:actionBarStyle">#style/ActionBarWithTitle</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.ActionBar">
<!-- Other ActionBar style elements. -->
<item name="android:displayOptions">showHome|useLogo</item>
</style>
<style name="ActionBarWithTitle" parent="ActionBar">
<item name="android:displayOptions">showHome|useLogo|showTitle</item>
</style>
</resources>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.themes"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.themes.Activity1"
android:theme="#style/AppThemeWithTitle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.themes.Activity2" />
<activity
android:name="com.example.themes.Activity3" />
</application>
</manifest>
Activity1 will have the title displayed but Activity2 and Activity3 will not.

Categories

Resources