我正在通过他页面上的教程学习 Android,但我遇到了部分问题:Running Your App章节。当我看到 activity_my.xml
预览时,我看到了“Hello world”文本,但是当我运行应用程序并看到模拟设备时,模拟器显示的设备只有黑页和“android”文本。我想我无法正常启动它,但在 Android Studio 控制台中我看到:
C:\Users\Abc\AppData\Local\Android\sdk\tools\emulator.exe
-avd Nexus_4_cale -netspeed full -netdelay none
creating window 208 44 800 480
emulator: emulator window was out of view and was recentered
这样看来还可以。但是,如果我选择编辑“app”配置,在 Target Device/Emulator
中,我会看到 Prefer Adroid Virtual Device
,在我的例子中,名为“Nexus_4_cale”,是红色的。但是如果我编辑这个设备没有错误等。我不知道发生了什么,如果有人愿意帮助我解决这个问题我会很高兴 - 提前谢谢你。
这就是它在模拟器中的样子:
这就是它在 Android Studio 预览中的样子:
这是配置,带有红色设备但没有解释:
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" />
MyActivity.java
类的代码:
package com.example.abc.android3;
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);
}
}
所有代码均由Android Studio生成
最佳答案
正在加载中。您必须等待加载完成。如果您的模拟器仍未启动,请通过 取消选中 Use Host Gpu
来编辑您的 emulator
配置。更多信息请查看 Can't start emulator for Android Studio
关于安卓工作室模拟器 : emulator shows only "android" text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29154525/