Android操作栏下拉菜单按钮无法显示

时间:2015-04-29 16:16:54

标签: android xml android-layout

我试图让菜单按钮显示在下面教程中的11:41。 https://www.youtube.com/watch?v=bsB2JUgXeGs?t=11m41s

这是我的代码:

first_layout.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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".FirstActivity"
    android:clickable="false">


    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView" />

</RelativeLayout>

styles.xml

<resources>

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

</resources>

的strings.xml

<resources>
    <string name="app_name">FirstApp</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
</resources>

FirstActivity.java

 package lj.com.firstapp;


    import android.os.Bundle;
    import android.support.v7.app.*;
    import android.view.Menu;
    import android.view.MenuItem;


    public class FirstActivity extends AppCompatActivity {

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

        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_first, 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();

            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }

            return super.onOptionsItemSelected(item);
        }
    }

我正在使用API​​ 22, 不确定我是否遗漏了某些东西,或者它是否假设看起来像这样? http://i.stack.imgur.com/GpYSW.png

1 个答案:

答案 0 :(得分:0)

显然没有问题。当我在模拟器中运行我的应用程序时,工具栏显示就像它想象的那样。它只是在android studio预览窗口中不活跃。

http://i.stack.imgur.com/Aky27.png