How can I make a custom progress bar in the action bar?

亡梦爱人 提交于 2019-12-21 17:52:35

问题


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>

回答1:


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.




回答2:


The LinearLayout surrounding the progress bar is unnecessary; also, notice that I added "expandActionView()" after setting the item's action view.

switch (item.getItemId()) {
    case R.id.refresh:
        item.setActionView(R.layout.progress);
        item.expandActionView();
        return true;

Have this in res/layout/progress.xml:

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleSmall"  
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</ProgressBar>

Technically, having a layout for this is unnecessary:

switch (item.getItemId()) {
    case R.id.refresh:
        item.setActionView(new ProgressBar(this, null, android.R.attr.progressBarStyleSmall));
        item.expandActionView();
        return true;


来源:https://stackoverflow.com/questions/6857364/how-can-i-make-a-custom-progress-bar-in-the-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!