How can I make a custom progress bar in the action

2019-04-09 19:16发布

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>

2条回答
我只想做你的唯一
2楼-- · 2019-04-09 19:54

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;
查看更多
乱世女痞
3楼-- · 2019-04-09 20:07

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.

查看更多
登录 后发表回答