Custom Action View can't be clicked

后端 未结 3 1010
广开言路
广开言路 2020-12-25 13:49

I am trying to add a custom ActionView to my ActionBar.

I am trying to add the common refresh button. (ImageButton, Prog

相关标签:
3条回答
  • 2020-12-25 14:13

    I ended up using the src code from http://code.google.com/p/styled-action-bar/.

    0 讨论(0)
  • 2020-12-25 14:17

    onOptionsItemSelected() should only be called if the action item is in the overflow menu which you should also handle. (you have it forced to "always" on action bar, so onOptionsItemSelected() won't get called).

    At onCreateOptionsMenu() after inflating, you must setup a OnMenuItemClickListener for the menu item.

    0 讨论(0)
  • 2020-12-25 14:40

    I have found a working solution for me and I want to share it with you. It's based on the first approach of (@Macarse), with some important changes.

    Important: adapt the initView method accordingly

    1. Set an onClickListener to the ImageView (mButton)

    2. Set loading to true & inform the Activity (MyActivity) about the click

      private void initView(final Context context) {
          final LayoutInflater inflator = LayoutInflater.from(context);
      
          final View actionView = inflator.inflate(
                  R.layout.action_refresh_progress, this);
          mProgressBar = (ProgressBar) actionView
                  .findViewById(R.id.action_refresh_progress);
      
          mButton = (ImageView) actionView
                  .findViewById(R.id.action_refresh_button);
      
          mButton.setOnClickListener(new OnClickListener() {
      
              @Override
              public void onClick(final View view) {
                  setLoading(true);
                  ((MyActivity) context).handleRefreshButtonClick();
              }
          });
      }
      
    3. React accordingly to the click in the Activity (MyActivity)

      public void handleRefreshButtonClick() {
          // Start refreshing...
      }
      

    I hope that my approach could save you some time finding a working solution!

    0 讨论(0)
提交回复
热议问题