3

次のように、ビューに水平進行状況バーを追加しようとしています。

res/menu.xml

<item   android:id="@+id/menuItemProgress"
        android:title="Progress"
        android:actionLayout="@layout/component_cancellable_progressbar"
        android:showAsAction="always"/>

component_cancellable_progressbar.xml

<FrameLayout    xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/searchProgressWrapper"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content">
<ProgressBar    android:id="@+id/searchProgress"
                android:layout_height="30dp"
                android:layout_width="150dp"
                style="@style/Custom.Widget.ProgressBar.Horizontal"
                android:max="100" />
<ImageView      android:id="@+id/cancelSearch"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content"
                android:paddingRight="8dp" 
                android:layout_gravity="right|center_vertical" 
                android:src="@android:drawable/ic_notification_clear_all"
                android:scaleType="fitXY" />
</FrameLayout>

Action 内からこの ProgressBar にアクセスするにはどうすればよいですか (Visisble / Invisible / Progress にするため)。

4

4 に答える 4

2

onCreateOptionsMenu をオーバーライドして、そこでビューをキャッチできます。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.getItem(0).getActionView();
  ...

またはIDを検索して

View v = (View) menu.findItem(R.id.search).getActionView();

アクションバーにカスタムドロップダウンメニューを挿入し、この方法でそれを制御することができました.

于 2013-07-22T21:52:24.740 に答える
2

onCreate() の後、通常のように findViewById() を介して簡単にアクセスできます。問題は別の原因で発生しました。

于 2011-08-17T10:42:19.660 に答える
-1

以下は、actionBar の非常に役立つリンクです。必要なものを実装できることを願っています。

http://thiranjith.wordpress.com/2011/07/15/actionbar-design-pattern-example-for-android/

public class ActionBar extends FrameLayout {

      private ProgressBar mProgress;



      public ActionBar(Context context, AttributeSet attrs) {

        super(context, attrs);

        mInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       FrameLayout barView = (RelativeLayout) mInflater.inflate(R.layout.actionbar, null);

        addView(barView);

       mProgress = (ProgressBar) barView.findViewById(R.id.actionbar_progress);

    public void showProgressBar() { ... }

    public void hideProgressBar() { ... }

    public boolean isProgressBarVisible() { ... }


}

次に、アクティビティから、次のようにプログレスバーを制御します。

public class MainActivity extends Activity {

    private ActionBar mActionBar;



    @Override

    public void onCreate(Bundle savedInstanceState) {
        mActionBar = (ActionBar) findViewById(R.id.actionBar);

        mActionBar.showProgressbar()

     }

}
于 2011-08-17T09:12:10.313 に答える