custom window title half blocked by tabPageIndicator - android

Im using JakeWharton-Android-ViewPagerIndicator in my application and i also created custom window title.
whem im trying ti run the app, i see that the custom title is half blocked by the rest of the activity.
http://postimg.org/image/c5w27rzj7/
this is part the main activity code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.layout_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
FragmentPagerAdapter adapter = new TubeFmAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
initEvents();
}
android manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TubeFM"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/WindowTitleTheme">
<activity
android:name="com.TubeFM.activities.MainActivity"
android:label="TubeFM"
android:screenOrientation="portrait"
android:theme="#style/Theme.PageIndicatorDefaults">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
android:exported="true"/>
</intent-filter>
<meta-data android:name="isLaunchableActivity" android:value="true"/>
</activity>
<activity
android:name="com.TubeFM.activities.VideoPlayerActivity"
android:label="#string/app_name"
android:exported="true"
android:screenOrientation="portrait">
</activity>
<meta-data android:name="isLaunchableActivity" android:value="false"/>
</application>
</manifest>
custom window title layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:paddingRight="5dip"
>
<ImageView
android:id="#+id/ic_search"
android:src="#drawable/ic_action_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<AutoCompleteTextView
android:id="#+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:background="#drawable/text_search_background"
android:hint="#string/search_artist"
android:imeOptions="actionSearch"
android:inputType="text"
android:visibility="invisible"
android:drawableRight="#drawable/ic_action_search">
</AutoCompleteTextView>
</LinearLayout>
</LinearLayout>
activity theme:
<resources>
<style name="Theme.PageIndicatorDefaults" parent="android:Theme">
<item name="vpiIconPageIndicatorStyle">#style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
</style>
<style name="Widget">
</style>
<style name="Widget.TabPageIndicator" parent="Widget">
<item name="android:gravity">center</item>
<item name="android:background">#drawable/vpi__tab_indicator</item>
<item name="android:paddingLeft">22dip</item>
<item name="android:paddingRight">22dip</item>
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
<item name="android:textAppearance">#style/TextAppearance.TabPageIndicator
</item>
<item name="android:textSize">11sp</item>
<item name="android:maxLines">1</item>
</style>
<style name="TextAppearance.TabPageIndicator" parent="Widget">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/vpi__dark_theme</item>
</style>
<style name="Widget.IconPageIndicator" parent="Widget">
<item name="android:layout_marginLeft">6dp</item>
<item name="android:layout_marginRight">6dp</item>
</style>
</resources>

ok , so who face the same problem.
the solution is to make that activity use theme parent android:theme to all the relevant styles.
e.g :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RidesTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#color/rides_window_title_bg</item>
</style>
<style name="SetRideTheme" parent="android:Theme">
<item name="android:windowTitleSize">56dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>

Related

android You cannot combine custom titles with other title features

I am using Android Studio 3.2 and Android API 23 develop the app, when I try to set a custom title bar it display the error You cannot combine custom titles with other title features.
I google the the error and try some answers on so, but it can't solve the problem, I am stucked.
the code is as following,
the manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shashiwang.shashiapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<!--<item name="windowActionBar">false</item>-->
</style>
<style name="TitleBarLayout" >
<item name="android:background">#color/colorTitleBarBg</item>
<item name="android:layout_height">#dimen/title_bar_height</item>
<item name="android:layout_width">match_parent</item>
</style>
<style name="TitleBarTitle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:color">#color/colorTitleBarTitle</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:text">#string/app_name</item>
<item name="android:textSize">#dimen/title_bar_title_font_size</item>
<item name="android:textStyle">bold</item>
</style>
<style name="TitleBarContactLayout">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginRight">10dp</item>
</style>
<style name="TitleBarContactIcon">
<item name="android:layout_width">#dimen/title_bar_contact_icon_width</item>
<item name="android:layout_height">#dimen/title_bar_contact_icon_height</item>
<item name="android:src">#drawable/ic_contact</item>
</style>
<style name="TitleBarContactText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:text">#string/title_bar_contact_text</item>
<item name="android:textSize">#dimen/title_bar_contact_font_size</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/titleBarContainer"
style="#style/TitleBarLayout">
<TextView
android:id="#+id/TitleBarTitle"
style="#style/TitleBarTitle" />
<LinearLayout
android:id="#+id/TitleBarContactContainer"
style="#style/TitleBarContactLayout">
<ImageView
android:id="#+id/titleBarContactIcon"
style="#style/TitleBarContactIcon" />
<TextView
android:id="#+id/TitleBarContactText"
style="#style/TitleBarContactText" />
</LinearLayout>
</RelativeLayout>
the activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar_layout);
}

How to customize title text of android activity

I'm trying to edit the Title text size because it changes when in landscape screen. I found changing the dimension in SP can solve the problem. So I did this...
added a style in style.xml
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">30sp</item>
</style>
and then in app_bar_main.xml under android.support.v7.widget.Toolbar i added this line
app:titleTextAppearance="#style/Toolbar.TitleText"
Now it gives the desired result on Main activity but all others activities are same. I have around 10 activities in my app. How can I change all the activities' Title? Please help. Thanks in advance.
my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/title_main"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".splash"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ch_1"
android:label="#string/ch_1" />
<activity
android:name=".ch_2"
android:label="#string/ch_2" />
<activity
android:name=".ch_3"
android:label="#string/ch_3" />
<activity
android:name=".ch_4"
android:label="#string/ch_4" />
<activity
android:name=".ch_5"
android:label="#string/ch_5" />
<activity
android:name=".ch_6"
android:label="#string/ch_6" />
<activity
android:name=".ch_7"
android:label="#string/ch_7" />
<activity
android:name=".ch_8"
android:label="#string/ch_8" />
<activity
android:name=".ch_9"
android:label="#string/ch_9" />
<activity
android:name=".ch_10"
android:label="#string/ch_10" />
<activity
android:name=".ch_11"
android:label="#string/ch_11" />
<activity android:name=".ch_12"
android:label="#string/ch_12" />
<activity
android:name=".ch_13"
android:label="#string/ch_13" />
<activity
android:name=".ch_14"
android:label="#string/ch_14" />
<activity
android:name=".ch_15"
android:label="#string/ch_15" />
<activity android:name=".view" />
</application>
my style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/white</item>
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="android:textAppearanceButton">#style/TextAppearance.AppCompat.Button.Custom</item>
</style>
<style name="Toolbar.TitleText"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">24sp</item>
</style>
<style name="TextAppearance.AppCompat.Button.Custom">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">28sp</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
You can use <include> tag to achieve it.
Just like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.dzq.aprivate.view.activity.MainActivity">
<include layout="#layout/lay_actionbar"/>
<FrameLayout
android:id="#+id/lay_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<include layout="#layout/lay_main_bottom"/>
</LinearLayout>
Use <include layout="#layout/toolbar_header"/> in every Activity you want.
Ok, I have resolved the issue. The previous code was not working for other layouts because activity_main.xml was using toolbar instead of action bar, so i had to write another piece of style for the action bar.
I added these style..
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">24sp</item>
</style>
and then added the item in AppTheme like this..
<item name="actionBarStyle">#style/MyActionBar</item>
and it's working fine now. Thanks everyone for replying.

Toolbar in CoordinatorLayout is invisible in Android 4.4( visible in Android 5.0 )

It's a layout with a toolbar,a webView and a floating actionButton(there should be a floating action button in android 5.0):
I'm using CoordinatorLayout because there's a floating action button in it. If change it to LinearLayout, action bar will be visible but the FloatingActionButton won't float on the screen. Changing CoordinatorLayout to FrameLayout doesn't make any change. How to deal with this?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_custom"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="outsideOverlay" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_favorite_white_24dp"
app:layout_behavior="com.drunkpiano.zhihuselection.utilities.ScrollingFavoriteFABBehavior" />
</android.support.design.widget.CoordinatorLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drunkpiano.zhihuselection">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.WebViewActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".activities.FavoritesActivity" />
<activity android:name=".activities.GuideActivity" />
<activity android:name=".activities.AnyActivity"></activity>
</application>
</manifest>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!--<item name="android:listDivider">#drawable/shape_divider</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ListItemText" parent="android:Widget.Holo.Light.TextView">
<item name="android:gravity">center</item>
<item name="android:layout_margin">5dip</item>
<item name="android:minLines">3</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="ThemeOverlay.YourApp" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="ActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>

ActionBar color not changing

I'm trying to change the color of the ActionBar in my app. The color was changed in the preview tap when opening the layout file, but not when I run it on my device (5.0.1). I need the status bar to be also colored.
Here is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="Test" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/primary_dark</item>
<item name="android:statusBarColor">#color/primary_dark</item>
<!--<item name="android:colorPrimary">#color/primary_dark</item>-->
<!--<item name="android:actionMenuTextColor">#FFFFFF</item>-->
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/primary_darker</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowBackground">#color/primary</item>
<item name="colorControlNormal">#color/iron</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
<item name="android:textColorHint">#color/iron</item>
<item name="colorButtonNormal">#color/primary_darker</item>
<item name="android:colorButtonNormal">#color/primary_darker</item>
</style>
<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimary">#color/iron</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
My manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.motassem.beacontest" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Material.Light.DarkActionBar" >
<activity
android:name=".TestActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".LoginActivity"
android:theme="#style/AppTheme.Dark" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignupActivity"
android:theme="#style/AppTheme.Dark" >
</activity>
<activity
android:name=".HomeActivity"
android:label="#string/title_activity_home" >
</activity>
</application>
</manifest>
My layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HomeActivity">
<fragment android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:id="#+id/frag_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/black" />
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" />
</LinearLayout>
And my fragment.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/string_total_saved"
android:id="#+id/tvTotal"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textSize="40sp"
android:id="#+id/textView2"
android:layout_below="#+id/tvTotal"
android:layout_centerHorizontal="true" />
Edit
After adding AppTheme in the solution's style.xml, the action bar is missing.
In your Activity (which has to extend an AppCompatActivity) or in your Application you should use a AppCompat Theme.
If you are not using a Toolbar in your layout use somenthing like:
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
</style>
Otherwise, if you are using a Toolbar use:
<style name="AppTheme.NoActionBar" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I added the following to style.xml and applied it for my activity
<style name="Accelerator" parent="#style/Theme.AppCompat">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/primary_dark</item>
<item name="colorControlHighlight">#color/primary_darker</item>
<item name="colorControlActivated">#color/white</item>
<item name="android:navigationBarColor">#color/primary</item>
<item name="android:statusBarColor">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/accent</item>
</style>

Progress Dialog not aligned in the ActionBarSherlock after API Level 11+

In my Project i have add Library ActionBar Sherlock and create the custom theme for my project.
I have created custom theme from here.
But after applying the theme my Progress Dialog in not aligned(means not displayed in the center of screen).
Please not this issue appears in API Level 11 or above.
Here i have attached the screen shot of emulator running OS 4.2.2.
I am unable to figure out this issue...
ScreenShot ::
MyCustomTheme ::(values folder)
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Custom_ThemeSherlockLight" parent="#style/Theme.Sherlock.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_exampthemesherlocklightle</item>
<item name="popupMenuStyle">#style/PopupMenu.Custom_ThemeSherlockLight</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Custom_ThemeSherlockLight</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Custom_ThemeSherlockLight</item>
<item name="actionDropDownStyle">#style/DropDownNav.Custom_ThemeSherlockLight</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Custom_ThemeSherlockLight</item>
<item name="actionModeBackground">#drawable/cab_background_top_exampthemesherlocklightle</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_exampthemesherlocklightle</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Custom_ThemeSherlockLight</item>
</style>
<style name="ActionBar.Solid.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_exampthemesherlocklightle</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_exampthemesherlocklightle</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_exampthemesherlocklightle</item>
<item name="progressBarStyle">#style/ProgressBar.Custom_ThemeSherlockLight</item>
</style>
<style name="ActionBar.Transparent.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="background">#drawable/ab_transparent_exampthemesherlocklightle</item>
<item name="progressBarStyle">#style/ProgressBar.Custom_ThemeSherlockLight</item>
</style>
<style name="PopupMenu.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
</style>
<style name="DropDownListView.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_exampthemesherlocklightle</item>
</style>
<style name="ActionBarTabStyle.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_exampthemesherlocklightle</item>
</style>
<style name="DropDownNav.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_exampthemesherlocklightle</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
<item name="android:dropDownSelector">#drawable/selectable_background_exampthemesherlocklightle</item>
</style>
<style name="ProgressBar.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_exampthemesherlocklightle</item>
</style>
<style name="ActionButton.CloseMode.Custom_ThemeSherlockLight" parent="#style/Widget.Sherlock.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_exampthemesherlocklightle</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Custom_ThemeSherlockLight.Widget" parent="#style/Theme.Sherlock">
<item name="popupMenuStyle">#style/PopupMenu.Custom_ThemeSherlockLight</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Custom_ThemeSherlockLight</item>
</style>
<style name="Theme.Sherlock.Translucent" parent="#style/Theme.Sherlock">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="Theme.Translucent" parent="#android:style/Theme.Translucent">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</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.testproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Custom_ThemeSherlockLight" >
<activity
android:name="com.example.testproject.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>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProgressDialog pDialog=new ProgressDialog(this);
pDialog =ProgressDialog.show(this,null, "Please Wait..", true);
pDialog.setContentView(R.layout.progress);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="130dp"
android:layout_height="80dp"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="center"
android:text="Please wait.."
android:textColor="#color/black" />
</LinearLayout>
Please change the following lines of code in
progress.xml file
android:layout_width="130dp"
android:layout_height="80dp"
to
android:layout_width="match_parent"
android:layout_height="match_parent"
It should display in the center of the screen now.
Hope this helps!
Edit: Please change the layout_width attribute of TextView to "wrap_content".
I don't know if it helps or not. But to fix the cropping issue of "Please wait" text. Change the layout_width to "wrap_content" like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="center"
android:text="Please wait.."
android:textColor="#color/black" />

Categories

Resources