R.变红了。我只是添加了另一个类/活动,我收到了一个错误 错误:(25)在包'com.androidbelieve.drawerwithswipetabs'中找不到属性'srcCompat'的资源标识符并且错误:(23,22)找不到与给定名称匹配的资源(在'layout'处,值为'@ layout / content_bodyache')。 和sample is attached 2错误:任务':app:processDebugResources'的执行失败。
package com.androidbelieve.drawerwithswipetabs;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity{
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
*Setup the DrawerLayout and NavigationView
*/
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
/**
* Lets inflate the very first fragment
* Here , we are inflating the TabFragment as the first Fragment
*/
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
/**
* Setup click events on the Navigation View Items.
*/
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
String title = "";
// Inserting navigation
if (menuItem.getItemId() == R.id.nav_item_sent) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new SentFragment()).commit();
title = "Emergency Hotline";
}
if (menuItem.getItemId() == R.id.nav_item_inbox) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new TabFragment()).commit(); //firstAid (health and life)
title = "First Aid and Survival Tips";
}
// [dito ipapasok ung sa map]
if (menuItem.getItemId() == R.id.nav_item_draft) {
/*FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new MapFragment()).commit(); //firstAid (health and life)*/
title = "Locate Hospital";
Intent i = new Intent(MainActivity.this, MapsActivity.class);
startActivity(i);
}
/* if (menuItem.getItemId() == R.id.nav_item_map) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new MapFragment()).commit(); //firstAid (health and life)
title = "Locate";
}*/
return false;
}
});
/**
* Setup Drawer Toggle of the Toolbar
*/
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
}
}
答案 0 :(得分:0)
不要使用:
android:srcCompat="@drawable/wallpaper"
做一些改变:
app:srcCompat="@drawable/wallpaper"
因为它(srcCompat
属性)实际上是在AppCompat库中定义的。
重要提示:您需要为此添加适当的命名空间。
xmlns:app="http://schemas.android.com/apk/res-auto"
你得到的似乎只是一个可以忽略的lint错误。我尝试过并遇到同样的错误,但它运行正常。
如果不起作用,您可以尝试
android:src="@drawable/wallpaper"