【发布时间】:2020-06-23 20:55:26
【问题描述】:
以下情况会导致模拟器中的安装后崩溃。没有显示调试信息。
package com.example.myapplication;
import android.os.Bundle;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.tabs.TabLayout;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import com.example.myapplication.ui.main.SectionsPagerAdapter;
public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.top_bar, menu);
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar top_toolbar = findViewById(R.id.top_toolbar);
setSupportActionBar(top_toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
BottomAppBar bottom_toolbar = findViewById(R.id.bottom_toolbar);
bottom_toolbar.replaceMenu(R.menu.bottom_bar);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
ImageButton my_posts_button = findViewById(R.id.my_posts_button);
ImageButton chats_button = findViewById(R.id.chats_button);
ImageButton post_button = findViewById(R.id.post_button);
ImageButton settings_button = findViewById(R.id.settings_button);
ImageButton profile_button = findViewById(R.id.profile_button);
ImageButton sort_button = findViewById(R.id.search_button);
ImageButton search_button = findViewById(R.id.sort_button);
}
}
看起来网站认为我的帖子主要是代码。看起来网站认为我的帖子主要是代码。看起来网站认为我的帖子主要是代码。
【问题讨论】:
-
2 个不同的操作栏?你能解释一下你想要达到的目标吗?
-
我有一个用于设置等的顶部栏和一个用于配置文件、聊天等(所有图标)的底部栏。我对 android studio 很陌生,所以我当然可能在选择方法时出错,而且我知道 python(自学)并且正在尝试学习用 java 制作应用程序。
标签: android android-studio android-toolbar android-bottomappbar