如何在操作栏中创建自定义进度条?

时间:2023-01-16 12:05:56

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

它不是动作栏,而是创建我需要帮助的自定义进度条。我想创建一个与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?

我已经尝试过多次不同的方式。我看了很多教程,包括Android Dev Guide。我在这一点上非常生气。有人会给我一些帮助吗?

Right now, my Action Bar is calling a generic progress bar layout and that works fine.

现在,我的Action Bar正在调用通用进度条布局,并且工作正常。

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 个解决方案

#1


2  

To make the progress bar show up, you need to turn on ActionBar.DISPLAY_SHOW_CUSTOM in ActionBar.displayOptions.

要显示进度条,您需要在ActionBar.displayOptions中打开ActionBar.DISPLAY_SHOW_CUSTOM。

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.

Catch笔记为其进度条使用自定义动画。我认为默认的Holo(正常大小)是一个合理的选择,但是为了得到类似于他们特定的东西,你需要创建一个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.

然后使用getCustomView()从ActionBar获取自定义视图,找到您的ImageView,并启动它动画。

#2


1  

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

围绕进度条的LinearLayout是不必要的;另外,请注意我在设置项目的操作视图后添加了“expandActionView()”。

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

Have this in res/layout/progress.xml:

在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;

#1


2  

To make the progress bar show up, you need to turn on ActionBar.DISPLAY_SHOW_CUSTOM in ActionBar.displayOptions.

要显示进度条,您需要在ActionBar.displayOptions中打开ActionBar.DISPLAY_SHOW_CUSTOM。

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.

Catch笔记为其进度条使用自定义动画。我认为默认的Holo(正常大小)是一个合理的选择,但是为了得到类似于他们特定的东西,你需要创建一个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.

然后使用getCustomView()从ActionBar获取自定义视图,找到您的ImageView,并启动它动画。

#2


1  

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

围绕进度条的LinearLayout是不必要的;另外,请注意我在设置项目的操作视图后添加了“expandActionView()”。

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

Have this in res/layout/progress.xml:

在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;