java如何删除“未找到与安卓:minHeight=“”匹配的资源”错误?属性/操作栏大小“
大家好,我正在制作一个应用程序,上面有Tabhost/Tabtoolbar,下面还有viewerpage。我的toolbar_layout.xml
文件中有错误
错误显示在安卓:minHeight="?安卓:attr/actionBarsize
行中,原因如下:
no resource found that matches the given name
每次在应用程序中创建新的片段java类和片段xml文件时,我都会遇到这个错误
下面是我的代码。Plz帮我解决这个错误,我在我的Android studio中使用Android 5.1版本
提前谢谢
工具栏布局xml文件
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.v7.widget.Toolbar
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent" 安卓:layout_height="wrap_content"
安卓:minHeight="?attr/actionBarsize"
安卓:background="?attr/colorPrimary"
安卓:fitsSystemWindows="true"
安卓:id="@+id/toolbar"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar">
</安卓.support.v7.widget.Toolbar>
主xml文件
<RelativeLayout
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context="com.example.mohammadzakriya.tabhost2.MainActivity">
<安卓.support.design.widget.AppBarLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
<include
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
layout="@layout/toolbar_layout"/>
<安卓.support.design.widget.TabLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:id="@+id/tabLayout"
app:tabMode="fixed"
app:tabGravity="fill"
></安卓.support.design.widget.TabLayout>
</安卓.support.design.widget.AppBarLayout>
<安卓.support.v4.view.ViewPager
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:id="@+id/viewPager"></安卓.support.v4.view.ViewPager>
</RelativeLayout>
维护性java文件
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
TabLayout tabLayout;
ViewPager viewPager;
ViewPagerAdapter viewPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar =(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
tabLayout =(TabLayout)findViewById(R.id.tabLayout);
viewPager =(ViewPager) findViewById(R.id.viewPager);
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPagerAdapter.addFragments(new HomeFragment(),"Home");
viewPagerAdapter.addFragments(new Database(),"Database");
viewPagerAdapter.addFragments(new contact(),"contact");
tabLayout.setupWithViewPager(viewPager);
}
}
查看页面适配器
public class ViewPagerAdapter extends FragmentPagerAdapter{
ArrayList<Fragment> fragments = new ArrayList<>();
ArrayList<String> tabTitles = new ArrayList<>();
public void addFragments(Fragment fragments,String titles){
this.fragments.add(fragments);
this.tabTitles.add(titles);
}
public ViewPagerAdapter(FragmentManager fm){
super(fm);
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles.get(position);
}
}
我的身材。gradle(模块:应用程序)
apply plugin: 'com.安卓.application'
安卓 {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.mohammadzakriya.tabhost2"
minSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-安卓.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.安卓.support:appcompat-v7:24.1.1'
compile 'com.安卓.support:design:24.1.1'
}
# 1 楼答案
改变这一点:
致:
请注意
actionBarSize
带有大写字母S
# 2 楼答案
使用
android:minHeight="?android:actionBarSize"