如何解决跨所有活动的浮动操作按钮,每个活动都有不同的实现
我希望在我的应用程序的每个活动中都有以下浮动操作按钮:
private void questionButton() {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab2);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(NewsHeadlines.this);
builder.setTitle("Do you want to delete this?");
//what is the message
builder.setMessage("Do something").setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
finish();
Toast.makeText(getApplicationContext(),"You chose yes",Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
finish();
Toast.makeText(getApplicationContext(),"you chose no",Toast.LENGTH_SHORT).show();
}
})
.create().show();
}
});
}
还有 xml:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/question_mark"
android:layout_margin="16dp" />
我尝试将此代码写入抽象的 BaseActivity 类,然后让我的其他类扩展 BaseActivity。我确保将基本活动布局包含到所有其他活动中:
<include layout="@layout/activity_base" />
但它一直崩溃。我忘记做什么了?
另外,我想知道如何对按钮进行编程以根据点击它的活动显示不同的消息。
任何想法将不胜感激。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。