我想创建应用程序,其中NavigationView和底部导航相互工作,但在输出中,我在“Run”中得到了下一个字符串
.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_container"
android:layout_above="@id/nav_bar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
layout="@layout/toolbar_main"
android:id="@+id/toolbar" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/nav_bar"
app:menu="@menu/bottom_navigation"
android:background="@color/colorWhite"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/toolbar_menu" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.nav_bar);
bottomNavigationView.setOnNavigationItemSelectedListener(navListener);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawer,
toolbar,
R.string.nav_open_drawer,
R.string.nav_close_drawer);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener((NavigationView.OnNavigationItemSelectedListener) this);
Fragment fragment = new AimsFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.content_frame, fragment);
ft.commit();;
}
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()){
case R.id.nav_veri:
selectedFragment = new AimsFragment();
break;
case R.id.nav_diary:
selectedFragment = new DiaryFragment();
break;
case R.id.nav_appoint:
selectedFragment = new CalendarFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,selectedFragment).commit();
return true;
}
};
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
Fragment fragment = null;
Intent intent = null;
switch(id){
case R.id.nav_aims:
fragment = new AimsFragment();
break;
case R.id.nav_reminder:
fragment = new ReminderFragment();
break;
case R.id.nav_statics:
fragment = new StaticsFragment();
break;
case R.id.nav_schedule:
fragment = new ScheduleFragment();
break;
case R.id.nav_project:
fragment = new ProjectFragment();
break;
case R.id.nav_settings:
fragment = new SettingsFragment();
break;
case R.id.nav_info:
fragment = new InfoFragment();
break;
default:
fragment = new AimsFragment();
}
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
} else {
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mederov.timelord"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
菜单
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_aims"
android:icon="@drawable/idea_aims"
android:title="@string/nav_aims"
android:checked="true" />
<item
android:id="@+id/nav_reminder"
android:icon="@drawable/reminder"
android:title="@string/nav_reminder" />
<item
android:id="@+id/nav_statics"
android:icon="@drawable/statics"
android:title="@string/nav_statics" />
<item
android:id="@+id/nav_schedule"
android:icon="@drawable/scheldule"
android:title="@string/nav_schedule" />
<item
android:id="@+id/nav_project"
android:icon="@drawable/project"
android:title="@string/nav_project" />
</group>
<menu>
<item
android:id="@+id/nav_settings"
android:icon="@drawable/settings"
android:title="@string/nav_settings" />
<item
android:id="@+id/nav_info"
android:icon="@drawable/info"
android:title="@string/nav_info"/>
</menu>
</menu>
请帮帮我,我不知道如何修复这个错误)
我也有同样的错误,我修复了它。问题是vector图标中的vector只在api级别21+上工作,如果你试着在api 19上运行它--他的意志不适合你。
我想创建一个应用程序,其中NavigationView和Bottom Navigation可以互相工作,但在输出中,我在“Run”中得到了下一个字符串。 .
我正在尝试制作一个可滚动的选项卡,但当我在我的片段布局中设置一个视图时,应用程序开始出现错误,因为错误inflating类为空。它在未添加视图时工作,但当我在布局中添加视图时,它会给我错误。我也按此处给出的那样添加了类,但它不起作用。我如何在这里修复这个问题是我的片段代码 片段包名称为包com。实例尼莱。另一个盒子。碎片片段名称歌曲。我怎样才能解决这个问题?错误 D/dalvikvm:GC_并发释
我试图实现方法底部导航视图,但当我运行代码时,我得到了这个错误 build.gradle(模块应用程序)
下面是我的布局: 编辑(已解决):最后,我找到了解决方案。应该在JAVA文件mapFragment中添加onDestroyView()方法,如下所示:
我得到了一个错误,这是我的XML文件 这里是styles.xml 我尝试将AppCompat更改为MaterialComponents,但它不起作用。但是当我指向LinearLayout标记(com.google.android.Material.TextField.TextInputLayout的父标记)时,它会用红线显示错误,当我移除LinearLayout标记时,它会消失。当我使用太多的Li
当我尝试构建我的android应用程序时,我如何修复这个问题。我将实现'com.google.android.gms:play-services-ads:19.8.0'更新为实现'com.google.android.gms:play-services-ads:20.4.0',现在我得到了这个错误。 jetified-play-services-measurement-18.0.2-runtime