繁体   English   中英

Android Studio:“我的第一个应用程序”不起作用

[英]Android Studio: “My First App” does not work

我绝对是Android开发的新手。

我正在按照本教程进行操作: https : //developer.android.com/training/basics/firstapp/running-app.html ,看来我无法在AVD上运行该应用程序,因为我看不到应用程序启动器图标或“ Hello world”文本。 它不会显示在“应用程序菜单”或“管理我的应用程序”窗口中。

我正在使用armeabi-v7a ABI为具有API Level 22(Android 5.1.1)的3.2 QVGA手机运行模拟器。

这是我得到的代码:

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gregory.myfirstapp" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MyActivity.java:

package com.example.gregory.myfirstapp;

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


public class MyActivity extends ActionBarActivity {

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

    @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_my, 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);
    }
}

activity_my.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=".MyActivity">

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

</RelativeLayout>

menu_my.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=".MyActivity">

    <item android:id="@+id/action_settings" 
    android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="never" />
</menu>

请帮我在这里!

我的Android Studio遇到了同样的问题。 我已经在“调试模式”(“播放”按钮旁边的绿色错误)下启动了该应用程序。 有时仿真器非常慢,因此您必须在解锁虚拟电话后等待5到50秒。 通常,该应用程序应在屏幕上自行打开,并且在首次运行后,该应用程序应显示在“应用程序菜单”中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM