如何设置圆形FAB按钮

问题描述 投票:0回答:1

enter image description here我正在尝试设置一个圆形 fab 按钮,单击该按钮会在圆形中显示其他选项,但在设置 setImageDrawable 时遇到一些错误 我正在使用编译时依赖 编译'com.oguzdev:CircularFloatingActionMenu:1.0.2'我的java代码是

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

   final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            SubActionButton.Builder itemBuilder = new SubActionButton.Builder(MainActivity.this);
            ImageView itemIcon = new ImageView(MainActivity.this);
            int id = getResources().getIdentifier("yourpackagename:drawable/" + step-forward, null, null);
            itemIcon.setImageDrawable(R.drawable.button_action);
            SubActionButton button1 = itemBuilder.setContentView(itemIcon).build();

        FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(MainActivity.this)
                .addSubActionView(button1)

                .attachTo(fab)
                .build();}
    });
}

} 我需要做哪些更改才能使子操作按钮起作用 当我使用

 ImageView icon = new ImageView(this);
icon.setImageDrawable( ... );
FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
.setContentView(icon)
.build();`

代替


     final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
 fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

声明 fab 按钮时我在构建中遇到错误 当我只使用这样的一个来源时

 ImageView icon = new ImageView(this); // Create an icon
            icon.setImageDrawable(R.drawable.step_forward );
            FloatingActionButton actionButton = new     FloatingActionButton.Builder(this)
                    .setContentView(icon)
                    .build();
            SubActionButton.Builder itemBuilder = new   SubActionButton.Builder(MainActivity.this);
            ImageView itemIcon = new ImageView(MainActivity.this);
            int id = getResources().getIdentifier("yourpackagename:drawable/" + step-forward, null, null);
            itemIcon.setImageDrawable(R.drawable.button_action);
            SubActionButton button1 = itemBuilder.setContentView(itemIcon).build();

        FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(MainActivity.this)
                .addSubActionView(button1)

                .attachTo(actionButton)
                .build();}

我在 FloatingActionButton.Builder(this) 中设置生成器时遇到错误 设置 setImageDrawable 时出错

android floating-action-button
1个回答
2
投票

我尝试使用的

FloatingActionButton
来自
com.android.support:design
,它没有
Builder()
方法。

您需要使用

FloatingActionButton
中的
com.oguzdev:CircularFloatingActionMenu

删除导入

android.support.design.widget.FloatingActionButton;
并添加

import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
无论您想在哪里使用 com.oguzdev:CircularFloatingActionMenu 的
FloatingActionButton

© www.soinside.com 2019 - 2024. All rights reserved.