繁体   English   中英

Android App不会在Android Studio模拟器中显示

[英]Android App won't display in Android Studio Emulator

我是Android开发的新手。 我试图重新创建一个应用程序,如果按下按钮,则会显示消息“新文本字符串”。 但是,当我运行AVD并选择虚拟设备时,它不会显示它。 我只有一个旧的TestApp。 有人可以建议修复吗? 我真的很感激。 我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=      "http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView android:id="@+id/hello_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />


<Button android:id="@+id/trigger"
    android:layout_width="100dip" android:layout_height="100dip"
    android:text="@string/button1"
    android:layout_below="@+id/hello_text"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="111dp" />
 </RelativeLayout>

SimpleActivity.java

package com.example.simpleactivityexample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.*;
import android.view.View;
public class SimpleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
    Button startButton = (Button) findViewById(R.id.trigger);
    startButton.setOnClickListener(new View.OnClickListener()
    {
        private TextView tv = (TextView) findViewById(R.id.hello_text);
        public void onClick(View view)
        {
            tv.setText("new text string");
        }
    }
    );

}
@Override
protected void onStart() {
    super.onStart();
    Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
    super.onResume();
    Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart() {
    super.onRestart();
    Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
    Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
    super.onPause();
}
@Override
protected void onStop() {
    Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
    super.onStop();
}
@Override
protected void onDestroy() {
    Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
    super.onDestroy();
}


}

表现

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

<application
    android:debuggable="true"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.simpleactivityexample.SimpleActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  </application>

 </manifest>

strings.xml中

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 <string name="app_name">Dietary Application</string>
 <string name="hello">Hello!</string>
 <string name="button1">This is a button!</string>
 </resources>

我设法解决了它。我顺便使用Android Studio。 我转到屏幕顶部的运行选项卡,然后进入“编辑配置”。 然后我勾选了''显示选择器对话框''。 我启动了AVD,当它完全启动时,A按下了运行功能(绿色三角形),它在Android上启动。 非常感谢所有帮助过的人!

你的代码似乎很好; 单击“作为Android应用程序运行”以检查安装是否正常,请检查logcat和控制台输出。

Logcat位于顶部菜单下

Window- Show View - 其他 - Android - Logcat

还尝试清理项目并重新启动模拟器; 而且,如果应用程序在模拟器加载时没有显示,请尝试在不退出模拟器的情况下再次运行它。

你在使用最新的工作室吗? 看起来像一个老虫

在Android Studio中运行模拟器时出错

尝试等待模拟器启动,然后运行该项目。

暂无
暂无

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

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