java - 不使用按钮自动打开底页
问题描述
我正在做这个项目,我想启动一个应用程序(主要活动),底部工作表作为了解如何使用某些功能的说明,而主要活动在后台打开。
我已经知道如何在底部表之间转换,但我的主要问题是第一个底部表需要一个按钮才能激活,所以我的问题是它可以在应用程序启动时自动完成而不需要按钮然后点击底部表格内的按钮后被解雇?
这是我的 Java 代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonShow = findViewById(R.id.button_start);
buttonShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
MainActivity.this, R.style.BottomSheetDesign
);
View bottomSheetView = LayoutInflater.from(getApplicationContext())
.inflate(
R.layout.layout_bottom_sheet,
(LinearLayout)findViewById(R.id.BottomSheetContainer)
);
bottomSheetView.findViewById(R.id.ButtonNext).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(
MainActivity.this, R.style.BottomSheetDesign
);
View bottomSheetView1 = LayoutInflater.from(getApplicationContext())
.inflate(
R.layout.layout_bottom_sheet1,
(LinearLayout)findViewById(R.id.BottomSheetContainer1)
);
bottomSheetView1.findViewById(R.id.ButtonDone).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetDialog1.dismiss();
}
});
bottomSheetDialog.dismiss();
bottomSheetDialog1.setContentView(bottomSheetView1);
bottomSheetDialog1.show();
}
});
bottomSheetDialog.setContentView(bottomSheetView);
bottomSheetDialog.show();
}
});
解决方案
在oncreate方法中直接调用bottomsheet
试试这个代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openBottomSheet();
}
private void openBottomSheet() {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
MainActivity.this, R.style.BottomSheetDesign
);
View bottomSheetView = LayoutInflater.from(getApplicationContext())
.inflate(
R.layout.layout_bottom_sheet,
(LinearLayout) findViewById(R.id.BottomSheetContainer)
);
bottomSheetView.findViewById(R.id.ButtonNext).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(
MainActivity.this, R.style.BottomSheetDesign
);
View bottomSheetView1 = LayoutInflater.from(getApplicationContext())
.inflate(
R.layout.layout_bottom_sheet1,
(LinearLayout) findViewById(R.id.BottomSheetContainer1)
);
bottomSheetView1.findViewById(R.id.ButtonDone).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetDialog1.dismiss();
}
});
bottomSheetDialog.dismiss();
bottomSheetDialog1.setContentView(bottomSheetView1);
bottomSheetDialog1.show();
}
});
bottomSheetDialog.setContentView(bottomSheetView);
bottomSheetDialog.show();
}
推荐阅读
- webpack - 通过 @import 或构建工具连接 scss 文件
- powershell - Azure 函数 v1 PowerShell - 如何访问请求标头?
- javascript - 如果条件不应该打开手风琴面板 - 咖啡脚本
- c++ - OpenCV 4.0 车道检测
- arrays - 如果我在抽屉上打开了抽屉,如何关闭抽屉?
- python - 使用 ffmpeg 或 Python 从视频中删除随机背景
- spring-boot - Feign:如何在spring中捕获API错误状态码
- angular - 角度搜索过滤器管道,用于全句搜索,而与词序无关
- cvxpy - CVXPY 产生奇怪的结果
- git - GIT 致命错误:Visual Studio 中的身份验证失败