如何在操作栏中制作自定义进度条?
与其说它是操作栏,不如说它是创建一个我需要帮助的自定义进度栏。我想创建一个与 Catch Notes 完全相同的 - https://ssl.gstatic.com/android /market/com. Threebanana.notes/ss-480-0-9 https://market.android.com/details?id=com. Threebanana .notes
我已经以多种不同的方式尝试了多次。我看过很多教程,包括 Android 开发指南。我现在非常生气。有人可以帮我吗?
现在,我的操作栏正在调用通用进度栏布局,并且效果很好。
switch (item.getItemId()) {
case R.id.refresh:
item.setActionView(R.layout.progress);
return true;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
</LinearLayout>
It's not so much the action bar, as much as it is creating a custom progress bar that I need help with. I want to create one exactly like Catch Notes -
https://ssl.gstatic.com/android/market/com.threebanana.notes/ss-480-0-9
https://market.android.com/details?id=com.threebanana.notes
I've tried multiple times in multiple different ways. I've looked at numerous tutorials including the Android Dev Guide. I'm pretty much angry at this point. Will someone offer me some help, please?
Right now, my Action Bar is calling a generic progress bar layout and that works fine.
switch (item.getItemId()) {
case R.id.refresh:
item.setActionView(R.layout.progress);
return true;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使进度条显示出来,需要在ActionBar.displayOptions中打开ActionBar.DISPLAY_SHOW_CUSTOM。
Catch Notes 使用自定义动画作为进度条。我认为默认的 Holo(正常大小)是一个合理的选择,但要获得类似于其特定的东西,您需要创建一个animationDrawable。
http://developer.android.com/reference/android/graphics/drawable /AnimationDrawable.html
然后使用 getCustomView() 从 ActionBar 获取自定义视图,找到您的 ImageView,并启动它的动画。
To make the progress bar show up, you need to turn on ActionBar.DISPLAY_SHOW_CUSTOM in ActionBar.displayOptions.
Catch notes is using a custom animation for their progress bar. I think that the default Holo (normal-sized) one is a reasonable alternative, but to get something like their specific one, you'll want to create an animationDrawable.
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Then get the custom view from the ActionBar with getCustomView(), find your ImageView, and start it animating.
进度条周围的 LinearLayout 是不必要的;另请注意,我在设置项目的操作视图后添加了“expandActionView()”。
在 res/layout/progress.xml 中包含此内容:
从技术上讲,为此设置布局是不必要的:
The LinearLayout surrounding the progress bar is unnecessary; also, notice that I added "expandActionView()" after setting the item's action view.
Have this in res/layout/progress.xml:
Technically, having a layout for this is unnecessary: