无法解析索引60处的属性

时间:2017-08-01 06:58:36

标签: java android android-layout android-tablayout android-design-library

我已经在我的应用中导入了扫描仪控制模块。我还正确添加了模块依赖项。我甚至可以访问导入模块的类。但问题是,每当我尝试打开该模块时(我已在主应用程序导航抽屉项中添加了该模块),看起来setContentView(R.layout.activity_active_scanner)存在问题。我认为主要问题在于tablayout(或其他xml部分)。

logcat如下所示:

Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 60
    at android.content.res.TypedArray.getColor(TypedArray.java:401)
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:348)
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:290)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
    at ****com.zebra.scannercontrol.app.activities.ActiveScannerActivity.onCreate(ActiveScannerActivity.java:79)**** 
    at android.app.Activity.performCreate(Activity.java:6092)  

并且activity_active_scanner的代码是:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_home_drawer" />

</android.support.v4.widget.DrawerLayout>  

及以下是我app_bar_active_scanner中包含的activity_active_scanner

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.zebra.scannercontrol.app.activities.ActiveScannerActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="@integer/abc_max_action_buttons"
            app:tabBackground="@color/blue"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/yellow"
            app:tabMaxWidth="0dp"
            app:tabMode="fixed"
            app:tabTextAppearance="@style/AppTabTextAppearance"/>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_activescanner" />

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

并在下面给出了ActiveScannerActivity,其中,我已声明/初始化并使用视图寻呼机设置tablayout。您可以忽略其他代码(我认为主要问题在于tablayout)。

public class ActiveScannerActivity extends BaseActivity implements  NavigationView.OnNavigationItemSelectedListener,
        ActionBar.TabListener,ScannerAppEngine.IScannerAppEngineDevEventsDelegate,ScannerAppEngine.IScannerAppEngineDevConnectionsDelegate{
    private ViewPager viewPager;
    ActiveScannerAdapter mAdapter;
    TabLayout tabLayout;
    private NavigationView navigationView;
    static int picklistMode;

    public boolean isPagerMotorAvailable() {
        return pagerMotorAvailable;
    }

    static boolean pagerMotorAvailable;
    private int scannerID;
    TextView barcodeCount;
    int iBarcodeCount;
    int  BARCODE_TAB = 1;
    int ADVANCED_TAB = 2;
    static MyAsyncTask cmdExecTask=null;
    Button btnFindScanner = null;
    static final int ENABLE_FIND_NEW_SCANNER =1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_active_scanner);

        Configuration configuration = getResources().getConfiguration();

        if(configuration.orientation == Configuration.ORIENTATION_LANDSCAPE){
            if(configuration.smallestScreenWidthDp<Application.minScreenWidth){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }else{
            if(configuration.screenWidthDp<Application.minScreenWidth){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }



        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.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        addDevConnectionsDelegate(this);
        scannerID = getIntent().getIntExtra(Constants.SCANNER_ID, -1);
        BaseActivity.lastConnectedScannerID = scannerID;
        String scannerName = getIntent().getStringExtra(Constants.SCANNER_NAME);
        String address = getIntent().getStringExtra(Constants.SCANNER_ADDRESS);

        picklistMode = getIntent().getIntExtra(Constants.PICKLIST_MODE, 0);

        pagerMotorAvailable = getIntent().getBooleanExtra(Constants.PAGER_MOTOR_STATUS,false);

        Application.CurScannerId = scannerID;
        Application.CurScannerName = scannerName;
        Application.CurScannerAddress = address;
        // Initilization
        viewPager = (ViewPager) findViewById(R.id.activeScannerPager);

        mAdapter= new ActiveScannerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);

        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        tabLayout.setupWithViewPager(viewPager);

0 个答案:

没有答案