我正在尝试让Android Studio 3.0.1中的浮动操作按钮转移到其他活动。我搜索的每个地方都没有主题。我是android studio和Java的新手。有人可以帮忙吗?谢谢!
* add是我要发布的活动的名称
到目前为止我所获得的代码是(在粗略的网站上):
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onClick:setAction(".add", null).show();
}
});

错误:
5 errors
FAILED
:app:buildInfoGeneratorDebug
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s

答案 0 :(得分:1)
为了帮助您入门,您可以找到有关如何添加浮动按钮here的文档。要使它在cliking之后启动一个新活动,请在监听器中添加指令:
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
startActivity(new Intent(this, YourNewActivity.class));
}
});
答案 1 :(得分:-1)
您需要在使用浮动操作按钮时使用Snackbar。
例 - >
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});