进度对话框在API级别后ActionBarSherlock没有对齐11+对话框、进度、级别、API

2023-09-04 03:17:09 作者:little eternity 小永远

在我的项目,我有添加库的ActionBar福尔摩斯和创建自定义主题,为我的项目。

我创建的自定义主题这里。 但是,应用的主题我的进度对话框中没有对齐(指屏幕的中心不显示)。在

请没有这个问题出现在API级别11或以上。 在这里,我附上了截屏模拟器运行OS 4.2.2。

我无法弄清楚这个问题...

截图::

MyCustomTheme::(值的文件夹)

 < XML版本=1.0编码=UTF-8&GT?;
<资源的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>


    <样式名称=Theme.Custom_ThemeSherlockLight父=@风格/ Theme.Sherlock.Light>
        &LT;项目name="actionBarItemBackground">@drawable/selectable_background_exampthemesherlocklightle</item>
        &LT;项目名称=popupMenuStyle&GT; @风格/ PopupMenu.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=dropDownListViewStyle&GT; @风格/ DropDownListView.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=actionBarTabStyle&GT; @风格/ ActionBarTabStyle.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=actionDropDownStyle&GT; @风格/ DropDownNav.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=actionBarStyle&GT; @风格/ ActionBar.Solid.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=actionModeBackground&GT; @可绘制/ cab_background_top_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目name="actionModeSplitBackground">@drawable/cab_background_bottom_exampthemesherlocklightle</item>
        &LT;项目name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Custom_ThemeSherlockLight</item>
    &LT; /风格&GT;

    &LT;样式名称=ActionBar.Solid.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ActionBar.Solid&GT;
        &LT;项目名称=背景&GT; @可绘制/ ab_solid_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目名称=backgroundStacked&GT; @可绘制/ ab_stacked_solid_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目名称=backgroundSplit&GT; @可绘制/ ab_bottom_solid_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目名称=progressBarStyle&GT; @风格/ ProgressBar.Custom_ThemeSherlockLight&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;样式名称=ActionBar.Transparent.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ActionBar&GT;
        &LT;项目名称=背景&GT; @可绘制/ ab_transparent_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目名称=progressBarStyle&GT; @风格/ ProgressBar.Custom_ThemeSherlockLight&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;样式名称=PopupMenu.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ListPopupWindow&GT;
        &LT;项目name="android:popupBackground">@drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
    &LT; /风格&GT;

    &LT;样式名称=DropDownListView.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ListView.DropDown&GT;
        &LT;项目name="android:listSelector">@drawable/selectable_background_exampthemesherlocklightle</item>
    &LT; /风格&GT;

    &LT;样式名称=ActionBarTabStyle.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ActionBar.TabView&GT;
        &LT;项目名称=机器人:背景&GT; @可绘制/ tab_indicator_ab_exampthemesherlocklightle&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;样式名称=DropDownNav.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.Spinner.DropDown.ActionBar&GT;
        &LT;项目名称=机器人:背景&GT; @可绘制/ spinner_background_ab_exampthemesherlocklightle&LT; /项目&GT;
        &LT;项目name="android:popupBackground">@drawable/menu_dropdown_panel_exampthemesherlocklightle</item>
        &LT;项目name="android:dropDownSelector">@drawable/selectable_background_exampthemesherlocklightle</item>
    &LT; /风格&GT;

    &LT;样式名称=ProgressBar.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ProgressBar.Horizo​​ntal&GT;
        &LT;项目name="android:progressDrawable">@drawable/progress_horizontal_exampthemesherlocklightle</item>
    &LT; /风格&GT;

    &LT;样式名称=ActionButton.CloseMode.Custom_ThemeSherlockLight父=@风格/ Widget.Sherlock.Light.ActionButton.CloseMode&GT;
        &LT;项目名称=机器人:背景&GT; @可绘制/ btn_cab_done_exampthemesherlocklightle&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;! - 这种风格只引用一个Light.DarkActionBar基于主题 - &GT;
    &LT;样式名称=Theme.Custom_ThemeSherlockLight.Widget父=@风格/ Theme.Sherlock&GT;
        &LT;项目名称=popupMenuStyle&GT; @风格/ PopupMenu.Custom_ThemeSherlockLight&LT; /项目&GT;
        &LT;项目名称=dropDownListViewStyle&GT; @风格/ DropDownListView.Custom_ThemeSherlockLight&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;样式名称=Theme.Sherlock.Translucent父=@风格/ Theme.Sherlock&GT;
        &LT;项目名称=机器人:windowIsTranslucent&GT;真&LT; /项目&GT;
        &LT;项目名称=机器人:windowContentOverlay&GT; @空&LT; /项目&GT;
        &LT;项目名称=机器人:windowNoTitle&GT;真&LT; /项目&GT;
        &LT;项目名称=机器人:windowIsFloating&GT;真&LT; /项目&GT;
        &LT;项目名称=机器人:windowBackground&GT; @android:彩色/透明&LT; /项目&GT;
        &LT;项目名称=机器人:backgroundDimEnabled&GT;假&LT; /项目&GT;
        &LT;项目名称=机器人:backgroundDimEnabled&GT;真&LT; /项目&GT;
    &LT; /风格&GT;

    &LT;样式名称=Theme.Translucent父=@安卓风格/ Theme.Translucent&GT;
        &LT;项目名称=机器人:windowBackground&GT; @android:彩色/透明&LT; /项目&GT;
        &LT;项目名称=机器人:windowNoTitle&GT;真&LT; /项目&GT;
        &LT;项目名称=机器人:backgroundDimEnabled&GT;真&LT; /项目&GT;
    &LT; /风格&GT;

&LT; /资源&GT;
 
Android进度及日期时间对话框以及显示设置的日期和时间

AndroidManifest.xml中::

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.testproject
    安卓版code =1
    机器人:VERSIONNAME =1.0&GT;

    &LT;用途-SDK
        安卓的minSdkVersion =7
        机器人:targetSdkVersion =17/&GT;

    &lt;应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ Theme.Custom_ThemeSherlockLight&GT;
        &LT;活动
            机器人:名称=com.example.testproject.MainActivity
            机器人:标签=@字符串/ APP_NAME&GT;
            &LT;意向滤光器&gt;
                &lt;作用机器人:名称=android.intent.action.MAIN/&GT;

                &LT;类机器人:名称=android.intent.category.LAUNCHER/&GT;
            &所述; /意图滤光器&gt;
        &LT; /活性GT;
    &LT; /用途&gt;

&LT; /舱单&GT;
 

MainActivity.java

 公共类MainActivity延伸活动{

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        ProgressDialog pDialog =新ProgressDialog(本);
        pDialog = ProgressDialog.show(本,空,请等待......,真正的);
        pDialog.setContentView(R.layout.progress);
    }

    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }

}
 

progress.xml

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =130dp
    机器人:layout_height =80dp
    机器人:背景=@机器人:彩色/透明
    机器人:重力=中心
    机器人:方向=垂直&GT;

    &LT;进度
        机器人:ID =@ + ID /进步
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/&GT;

    &LT;的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginTop =5dip
        机器人:重力=中心
        机器人:文本=请等待......
        机器人:文字颜色=@彩色/黑白/&GT;

&LT; / LinearLayout中&GT;
 

解决方案

请更改code以下行的

  

progress.xml文件

 机器人:layout_width =130dp
机器人:layout_height =80dp
 

 机器人:layout_width =match_parent
机器人:layout_height =match_parent
 

它应该在屏幕的中心,现在显示。

希望这有助于!

编辑:请改变的TextView的layout_width属性设置为WRAP_CONTENT

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