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

2

0

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

enter image description here

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>
Population answered 16/12, 2013 at 8:50 Comment(0)
E
1

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

Epistemic answered 24/12, 2013 at 10:37 Comment(3)
Bingo !!!!!!! Solved... But if i run after applying your changes,then text view display only half(instead of display "please wait.." it display only "Please").Population
I have tested it on device running Android 4.0.4 and I can see the complete text "Please wait...". Let me know your test environment.Epistemic
Please change the layout_width attribute of TextView to "wrap_content". It should work.Epistemic
Q
1

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" />
Qr answered 24/12, 2013 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.