如何设置圆形FAB按钮

时间:2016-04-19 17:48:39

标签: android floating-action-button

enter image description here我试图设置一个循环制作按钮,点击显示循环中的其他选项但我在设置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)设置Builder时遇到错误 设置setImageDrawable

时出错

1 个答案:

答案 0 :(得分: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' s FloatingActionButton