【问题标题】:How to remove the Error of "no resource found that matches android:minHeight="?attr/actionBarsize"如何删除“找不到与 android:minHeight="?attr/actionBarsize" 匹配的资源的错误
【发布时间】:2016-12-05 17:50:03
【问题描述】:

大家好,我正在制作一个顶部有 Tabhost/Tabtoolbar 的应用程序,它的下方还有查看器页面。我的toolbar_layout.xml 文件中面临错误

错误显示在android:minHeight="?android:attr/actionBarsize 行中,原因是:

找不到与给定名称匹配的资源

每次在应用程序中创建新的 Fragment java 类和 Fragment xml 文件时都会遇到此错误

下面是我的代码。请帮我解决这个错误,并在我的 Android 工作室中使用 Android 5.1 版本进行此操作

提前致谢

工具栏布局xml文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarsize"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:id="@+id/toolbar"
    app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar">

</android.support.v7.widget.Toolbar>

主xml文件

<RelativeLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mohammadzakriya.tabhost2.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/toolbar_layout"/>

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabLayout"
            app:tabMode="fixed"
            app:tabGravity="fill"
            ></android.support.design.widget.TabLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/viewPager"></android.support.v4.view.ViewPager>
</RelativeLayout>

MainAcivity 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);

    }
}

ViewPage 适配器

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);
    }
}

我的 build.gradle(模块:应用程序)

apply plugin: 'com.android.application'

android {
    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-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
}

【问题讨论】:

  • Java !== JavaScript

标签: java android


【解决方案1】:

改变这个:

android:minHeight="?attr/actionBarsize"

收件人:

android:minHeight="?attr/actionBarSize"

注意是actionBarSize,大写S

【讨论】:

  • 感谢由于这个小错误而面临错误。您提到的更改实际上有效并执行了项目谢谢
  • @MohammadZakriya 很高兴知道!!!很高兴我能帮助你。我只是请求接受答案,因为它解决了您的问题...提前致谢
【解决方案2】:

使用android:minHeight="?android:actionBarSize"

【讨论】:

  • 在您的代码中,您使用的 ?attr/actionBarsize?android:actionBarSize 不同。尝试更改为?android:actionBarSize 然后进行测试。
  • 你正在使用 ?attr/actionBarsize。并应用了你提到的编辑,但错误似乎仍然存在
  • 也要注意区分大小写,检查你的命名空间是xmlns:android="http://schemas.android.com/apk/res/android"。然后清理-> 重建你的项目。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-19
  • 2018-05-25
  • 2017-10-13
  • 2018-03-21
相关资源
最近更新 更多