Mat*_*ska 18 android android-progressbar android-actionbar
我想在操作栏上设置progressBar但是设置
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
Run Code Online (Sandbox Code Playgroud)
on onCreate方法产生一个中等大小的progressBar(48dip x 48dip)我想.我想改变progressBar的大小,但我找不到如何做到这一点.你能帮我吗?
adn*_*eal 28
您需要创建自己的样式以应用于ActionBar.在Android开发者博客上有一个很好的教程.要设置中间进度条的样式,请尝试使用indeterminateProgressStyle和Widget.ProgressBar.Small.这是一个简单的例子.
<style name="YourTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBarIPS</item>
</style>
<style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar">
<item name="android:indeterminateDrawable">@drawable/ic_launcher</item>
</style>
<style name="ActionBarIPS" parent="@android:style/Widget.ActionBar">
<item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item>
<item name="android:background">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
小智 15
1.定义res/values/styles.xml(此示例使用Sherlock库在旧的Android版本中提供操作栏,因此,如果您不使用Sherlock,则应使用适当的父级来定义自定义样式):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item>
<item name="indeterminateProgressStyle">@style/IndeterminateProgress</item>
</style>
<style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small">
<item name="android:indeterminateDrawable">@drawable/progress_indeterminate_custom</item>
</style>
</resource>
Run Code Online (Sandbox Code Playgroud)
2.define res/drawable/progress_indeterminate_custom.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:drawable="@drawable/ic_progress_logo1"
android:fillAfter="true"
android:fromDegrees="-180"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="180" />
</item>
<item>
<rotate
android:drawable="@drawable/ic_progress_logo2"
android:fillAfter="true"
android:fromDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-180" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
3.以上代码使用2个图像(ic_progress_logo1和ic_progress_logo2)作为自定义进度不确定图标.您可以通过添加新的项目元素来使用尽可能多的图像/绘图.此外,您可以应用不同的效果/动画.更多信息:动画资源
4.使用AndroidManifest.xml创建的应用样式:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".application.MyApplication">
<activity
android:name=".activities.MyActivity"
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>
</application>
Run Code Online (Sandbox Code Playgroud)
5.享受您的动画自定义进度不确定图标:D
我努力使用所有这些解决方案,因为我没有使用actionbarsherlock.我利用Vlasto Benny Lava的答案,最初对我不起作用.
这是我一步一步做的:
1)打开你的styles.xml文件,它应该在/res/values/styles.xml.如果它不存在则创建它.
2) 粘贴:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">@style/ActionBar.MyStyle</item>
</style>
<style name="ActionBar.MyStyle" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:indeterminateProgressStyle">@style/ActionBarProgressBar.MyStyle</item>
</style>
<style name="ActionBarProgressBar.MyStyle" parent="@android:style/Widget.Holo.ProgressBar.Small">
<item name="android:minWidth">28dp</item>
<item name="android:maxWidth">28dp</item>
<item name="android:minHeight">28dp</item>
<item name="android:maxHeight">28dp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
我遇到过一个catchya,你不能使用主题名称"AppTheme",否则覆盖将无效.我用了"MyTheme".这个主题是使用Holo所以它有一个黑色的ActionBar,如下图所示.如果你想有一个白色的动作条的话当然替换android:Theme.Holo用android:Theme.Holo.Light等.
3)编辑AndroidManifest.xml.
您<application>必须包含,android:theme="@style/myTheme"以便应用程序使用您的覆盖样式styles.xml
即,我的清单应用程序标记文件看起来像这样:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/myTheme"
android:name="Application Name Here" >
Run Code Online (Sandbox Code Playgroud)
因为您只是缩小现有进度png的大小,所以无需导出任何图像并将其移动到可绘制位置等.
这就是我的样子,图标的大小对我来说是完美的.

| 归档时间: |
|
| 查看次数: |
31919 次 |
| 最近记录: |