0

我使用下面的代码实现了一个浮动操作按钮,它有 5 个子操作按钮,我如何为每个子操作按钮添加一个 onClickListener 以便当您单击时应该打开不同的活动。

 SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    ImageView rlIcon4 = new ImageView(this);
    ImageView rlIcon5 = new ImageView(this);
    //ImageView rlIcon6 = new ImageView(this);

     rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_contact));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_currency_info));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_exhibition));
    rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_faq));
    rlIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_info_desk));
    //rlIcon6.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_passport));



    // Build the menu with default options: light theme, 90 degrees, 72dp radius.
    // Set 4 default SubActionButtons
    final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this)
            .addSubActionView(rLSubBuilder.setContentView(rlIcon1).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon2).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon3).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon4).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon5).build())
            //.addSubActionView(rLSubBuilder.setContentView(rlIcon6).build())
            .attachTo(rightLowerButton)
            .build();

    // Listen menu open and close events to animate the button content view
    rightLowerMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {
        @Override
        public void onMenuOpened(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees clockwise
            fabIconNew.setRotation(0);
            PropertyValuesHolder pvhR =  PropertyValuesHolder.ofFloat(View.ROTATION, 90);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }

        @Override
        public void onMenuClosed(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees counter-clockwise
            fabIconNew.setRotation(90);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
            ObjectAnimator animation =  ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }
    });

}
4

2 回答 2

1

尝试:

SubActionButton button1 = rLSubBuilder.setContentView(rlIcon1).build();
SubActionButton button2 = rLSubBuilder.setContentView(rlIcon2).build();
[...]
SubActionButton buttonN = {...}

button1.setOnClickListener(...);
button2.setOnClickListener(...);
[...]

 final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this)
            .addSubActionView(button1)
            .addSubActionView(button2)
            .addSubActionView(rLSubBuilder.setContentView(rlIcon3).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon4).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon5).build())
            //.addSubActionView(rLSubBuilder.setContentView(rlIcon6).build())
            .attachTo(rightLowerButton)
            .build();
于 2015-10-18T18:59:33.407 回答
0

我假设您正在使用这个。查看源代码,您可以看到setContentView只是将视图添加到CircularActionMenu派生自FrameLayout. 因此,设置onClickListenersImageViews打开新活动应该这样做。这就是你的 onClickListeners 应该是什么样子

rIIcon1.setOnClickListener(new View.OnCLickListener(){
    @Override
    public void onClick(View view){
       Intent intent = new Intent(getApplicationContext(),ActivityName.class)
       startActivity(intent)
    }
})

同样将侦听器附加到其他图像视图

于 2015-10-18T17:52:42.577 回答