【问题标题】:Issues while running App developed using Android Material Design运行使用 Android Material Design 开发的应用时出现的问题
【发布时间】:2015-10-23 08:25:22
【问题描述】:

我一直在使用 ma​​terial design 开发一个应用程序。我对此完全陌生。我一直在寻找本教程以供参考 material design 。但是我没有在工具栏的右上角显示“设置”选项。工具栏正在显示,但不是“3 点设置”按钮。我遵循与教程相同的方法,但我不知道为什么没有显示设置。 这是我的 styles.xml 代码:

 <resources>

    <!-- Base application theme. -->
   <style name="AppTheme" parent="AppTheme.Base">
      <!-- Customize your theme here. -->
   </style>

      <style name="AppTheme.Base" parent="Theme.AppCompat.Light">

      </style>
 </resources>

和我的 styles.xml(v-21) 代码:

 <?xml version="1.0" encoding="utf-8"?>
     <resources>
        <style name="AppTheme" parent="AppTheme.Base">
        </style>

我的 build.gradle 看起来像这样:

  apply plugin: 'com.android.application'

  android {
  compileSdkVersion 21
  buildToolsVersion "21.0.1"

   defaultConfig {
    applicationId "app.xxx.yyy.myapplication"
    minSdkVersion 15
    targetSdkVersion 21
    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:21.0.+'
  }

我附上了我得到的结果的图像。请帮助我度过难关!

【问题讨论】:

  • 分享您的 MainActivity 代码。

标签: android material-design


【解决方案1】:

我认为问题不在于材料,而在于工具栏或选项菜单。如果可能,您应该分享您的 mainActivity 代码。

【讨论】:

  • 我只想显示设置。我没有在我的主要活动中开始任何事情。
  • 设置按钮是optionsMenu的一个菜单项。您能否检查方法 onCreateOptionsMenu 是否已在 MainActivity 中被覆盖?
【解决方案2】:

用它检查你的代码... 菜单.xml

<menu 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"
    tools:context="com.example.toolbar.MainActivity" >
 <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="ifRoom"/>

</menu>

MainActivity.java

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
        setSupportActionBar(toolbar);
       // toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setLogo(R.drawable.ic_launcher);
        //toolbar.setTitle("Title");
       // toolbar.setSubtitle("Subtitle");





    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

activity_main.xml

<RelativeLayout 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.toolbar.MainActivity" >

     <android.support.v7.widget.Toolbar
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:id="@+id/my_awesome_toolbar"
         android:layout_width="fill_parent"
         android:layout_height="128dp"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:background="?attr/colorPrimary"
         android:minHeight="?attr/actionBarSize"
         app:theme="@style/ActionBarThemeOverlay">
     </android.support.v7.widget.Toolbar>



</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-07
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多