材料设计,带导航抽屉,滑动标签和卡片

时间:2015-11-25 07:59:55

标签: android material-design

我正在使用AIDE,我从hmkcode.com获得了示例代码。但我有13个错误。在styles.xml中有4个,其余的在MainActivity.java中

styles.xml

错误*

* aapt:检索项目的父项时出错:找不到与给定名称匹配的资源' Theme.Appcompat.NoActionBar'。

* aapt:找不到与给定名称匹配的资源:attr' colorAccent'。

* aapt:找不到与给定名称匹配的资源:attr' colorPrimary'。

* aapt:找不到与给定名称匹配的资源:attr' colorPrimaryDark'

<resources>

<style name="Base.Theme.HMKCodeApp" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/my_primary</item>

    <!--   darker variant for the status bar and contextual app bars -->
    <item name="colorPrimaryDark">@color/my_primary_dark</item>

    <!--   theme UI controls like checkboxes and text fields e.g. FloatActionButton -->
    <item name="colorAccent">@color/my_accent</item>

    <!-- Title Text Color -->
    <item name="android:textColorPrimary">@color/my_primary_text</item> 

    <!-- color of the menu overflow icon (three vertical dots) -->
    <item name="android:textColorSecondary">@color/my_secondary_text</item>  


   <item name="android:windowBackground">@color/window_background</item> 
</style>

 <!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
 <style name="AppBaseTheme" parent="Base.Theme.HMKCodeApp">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


  <style name="Widget.CardContent" parent="android:Widget">
    <item name="android:paddingLeft">16dp</item>
    <item name="android:paddingRight">16dp</item>
    <item name="android:paddingTop">24dp</item>
    <item name="android:paddingBottom">24dp</item>
    <item name="android:orientation">vertical</item>
</style>

MainActivity.java

我在这里遇到的错误是未知错误&#39; R&#39; 。所有R.layout ......

package com.hmkcode.app;

import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends AppCompatActivity implements OnClickListener {

DrawerLayout drawerLayout;
CollapsingToolbarLayout collapsingToolbarLayout;
Toolbar toolbar;
TabLayout tabLayout;
FloatingActionButton fab;

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

    setupNavigationView();
    setupToolbar();
    setupTablayout();
    setupCollapsingToolbarLayout();
    setupFab();

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            if(drawerLayout != null)
                drawerLayout.openDrawer(GravityCompat.START);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

private void setupNavigationView(){

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
}

private void setupCollapsingToolbarLayout(){

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    if(collapsingToolbarLayout != null){
        collapsingToolbarLayout.setTitle(toolbar.getTitle());
        //collapsingToolbarLayout.setCollapsedTitleTextColor(0xED1C24); 
        //collapsingToolbarLayout.setExpandedTitleColor(0xED1C24);
    }
}

private void setupTablayout(){

    tabLayout = (TabLayout) findViewById(R.id.tabLayout);

    if(tabLayout == null)
        return;

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
    tabLayout.addTab(tabLayout.newTab().setText("Tab 4"));
}

private void setupFab(){
    fab = (FloatingActionButton) findViewById(R.id.fab);
    if(fab != null)
        fab.setOnClickListener(this);
}
private void setupToolbar(){
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(toolbar != null)
        setSupportActionBar(toolbar);

    // Show menu icon
    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
}

@Override
public void onClick(View view) {

    if(view.getId() == R.id.fab){

        Snackbar
          .make(findViewById(R.id.coordinatorLayout), "This is Snackbar", Snackbar.LENGTH_LONG)
          .setAction("Action", this)
          .show(); // Don�t forget to show!
    }
}

}

我还添加了所需的库,但我得到了错误。这是我的源代码Material design code

感谢您的帮助。

0 个答案:

没有答案