我想创建一个应用程序,其中NavigationView和Bottom Navigation可以互相工作,但在输出中,我在“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>
我也犯了同样错误,我把它修好了。问题是在向量图标,向量只能在api级别21+上工作,如果你试着在api 19上运行它-他的意志对你不起作用。
我想创建应用程序,其中NavigationView和底部导航相互工作,但在输出中,我在“Run”中得到了下一个字符串 . 菜单 请帮帮我,我不知道如何修复这个错误)
问题内容: 您好,我是android dev和admob的新手。我正在尝试制作一个带有按钮,几个页面和底部的admob的简单测试应用程序。一切正常,直到我尝试实施admob。这是我的代码: HelloAndroid.java: main.xml: 您好android清单: logcat输出: 我正在使用GoogleAdMobAdsSdkAndroid-6.0.0。再次,我对此非常陌生,我尝试在多个
问题内容: 错误日志: 10-26 12:22:33.144 26926-26926 /?E / AndroidRuntime:致命例外:主进程:ksmk.sahip.com.ecom,PID:26926 java.lang.RuntimeException:无法启动活动ComponentInfo {ksmk.sahip.com.ecom / ksmk.sahip.com.ecom.MainAct
问题内容: 尝试运行我的应用程序时,我意外地遇到了以下错误: 下面是日志猫: 以下是Java代码: 下面是布局代码: 提前致谢 问题答案: 我通过在app / build.gradle上添加更新的cardview和appcompat解决了这一问题 然后重建项目
问题内容: 我正在尝试创建一个扩展的自定义视图。这是我的班级定义文件 : 这是在我的ghostviewscreen.xml中: 现在,我在活动中进行了: 当被调用时,抛出一个异常: 谁能告诉我为什么会出现此错误?谢谢。 问题答案: 我想我弄清楚了为什么这没用。当我应该为两个参数“ Context,AttributeSet”的情况提供构造函数时,我只为一个参数“ context”的情况提供了构造函数
我试图将我的GLSurfaceView设置在xml布局以及其他UI元素上,并不断获得错误inflating类com.vi.cubo01。MyGLSurfaceView在LogCat. 以下是java代码: 以及xml: