Android的工作室在菜单应用不显示 [英] Android Studio Menu not showing in app

查看:146
本文介绍了Android的工作室在菜单应用不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我的操作菜单在我的Andr​​oid工作室应用dissapeared。我下面的教程来学习如何创建一个Android应用程序,但我结束了这个问题。

For some reason my action menu dissapeared in my Android Studio app. I'm following a tutorial to learn how to create an android app but I ended up with this problem.

教程中,我使用ATM: HTTP:// WWW .raywenderlich.com / 56109 /让先的Andr​​oid应用部分-2

Tutorial I'm using atm: http://www.raywenderlich.com/56109/make-first-android-app-part-2

这是我的main.xml如下:

This is what my main.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Share item -->
    <item
        android:id="@+id/menu_item_share"
        android:showAsAction="ifRoom"
        android:title="Share"
        android:actionProviderClass= "android.widget.ShareActionProvider" />
</menu>

menu_main.xml:

menu_main.xml:

<!-- Defines the menu item that will appear on the Action Bar in MainActivity -->
<menu xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Share item -->
    <item
        android:id="@+id/menu_item_share"
        android:showAsAction="ifRoom"
        android:title="Share"
        android:actionProviderClass= "android.widget.ShareActionProvider"
        tools:ignore="AppCompatResource" />
</menu>

我做了什么错在这code?我没有得到任何错误。我pretty多复制本教程粘贴此。

What did I do wrong in this code? I didn't get any errors. And I pretty much copy pasted this from the tutorial.

我不认为它我的Java code,但这里仍然是柜面有人认为这个问题是在code。 MainActivity.java:

I don't think its my java code but still here it is incase someone thinks the problem is in that code. MainActivity.java:

package android.stefan.testappnieuw;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;


public class MainActivity extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {

    TextView mainTextView;
    Button mainButton;
    EditText mainEditText;
    ListView mainListView;
    ArrayAdapter mArrayAdapter;
    ArrayList mNameList = new ArrayList();
    android.widget.ShareActionProvider mShareActionProvider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 1. Access the TextView defined in layout XML
        // and then set its text
        mainTextView = (TextView) findViewById(R.id.main_textview);
        mainTextView.setText("Set in Java!");
        // 2. Access the Button defined in layout XML
        // and listen for it here
        mainButton = (Button) findViewById(R.id.main_button);
        mainButton.setOnClickListener(this);
        // 3. Access the EditText defined in layout XML
        mainEditText = (EditText) findViewById(R.id.main_edittext);
        // 4. Access the ListView
        mainListView = (ListView) findViewById(R.id.main_listview);
        // 5. Set this activity to react to list items being pressed
        mainListView.setOnItemClickListener(this);

        // Create an ArrayAdapter for the ListView
        mArrayAdapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_1,
                mNameList);

        // Set the ListView to use the ArrayAdapter
        mainListView.setAdapter(mArrayAdapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu.
        // Adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

        // Access the Share Item defined in menu XML
        MenuItem shareItem = menu.findItem(R.id.menu_item_share);

        // Access the object responsible for
        // putting together the sharing submenu
        if (shareItem != null) {
            mShareActionProvider = (android.widget.ShareActionProvider)shareItem.getActionProvider();
        }

        // Create an Intent to share your content
        setShareIntent();

        return true;
    }

    private void setShareIntent() {

        if (mShareActionProvider != null) {

            // create an Intent with the contents of the TextView
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Android Development");
            shareIntent.putExtra(Intent.EXTRA_TEXT, mainTextView.getText());

            // Make sure the provider knows
            // it should work with that Intent
            mShareActionProvider.setShareIntent(shareIntent);
        }
    }

    @Override
    public void onClick(View v) {
        // Take what was typed into the EditText
        // and use in TextView
        mainTextView.setText(mainEditText.getText().toString()
                + " Hallo");
        // Also add that value to the list shown in the ListView
        mNameList.add(mainEditText.getText().toString());
        mArrayAdapter.notifyDataSetChanged();
        // 6. The text you'd like to share has changed,
        // and you need to update
        setShareIntent();
    }

    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        // Log the item's position and contents
        // to the console in Debug
        Log.d("omg android", position + ": " + mNameList.get(position));
    }
}

我真的不知道什么是错我是新来的Java / Android和出于某种原因,菜单栏显示出来的教程,但不适合我。

I really have no idea whats wrong I'm new to java/android and for some reason the menu bar is showing up in the tutorial but not for me.

感谢您的阅读/帮助!

推荐答案

去你的清单文件,添加或更改此应用程序的属性,如果没有可用外观类似的东西还有更多的使用操作栏

go to your manifest file and add or change this application attribute, if not available look for something similar there are more using action bar

android:theme="@style/ThemeOverlay.AppCompat.ActionBar" >

这篇关于Android的工作室在菜单应用不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆