应用程序名称是 Eclipse MainActivity?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11635749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:39:53  来源:igfitidea点击:

App Name is Eclipse MainActivity?

androideclipseandroid-layoutandroid-emulatorandroid-activity

提问by PrommeringsDisplay

I have finished a tip calculator app, but when I run it the name is MainActivity, I don't know how to change it, I have tried editing strings.xmlbut when I run the app I get errors,I don't know what else to try, any suggestions for what I can do to change it so it appears on the emulator

我已经完成小费计算器应用程序,但是当我运行它的名字是MainActivity,我不知道如何去改变它,我试图编辑strings.xml但是当我运行该应用程序我得到的错误,我不知道还有什么尝试,关于我可以做些什么来改变它的任何建议,以便它出现在模拟器上

on strings.xml...

在strings.xml...

name:title_activity_mainvalue:MainActivity

名称:title_activity_main值:MainActivity

also here is my java code will i have to change anything here?

这也是我的 java 代码,我必须在这里更改任何内容吗?

package tip.calculator;


import android.os.Bundle;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import android.widget.Button;
import java.text.DecimalFormat;

public class TipCalculator extends Activity 
{
private EditText myEditField;
private EditText myEditField2;
private Button enter;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myEditField2 = (EditText) findViewById(R.id.billText);
    myEditField = (EditText) findViewById(R.id.percentText);
    enter = (Button)findViewById(R.id.button1);

    enter.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            TextView textView;

            textView = (TextView) findViewById(R.id.textView1);

            final EditText myEditField = (EditText) findViewById(R.id.percentText);
            final EditText myEditField2 = (EditText) findViewById(R.id.billText);

            float percentage;
            float percentageInp;
            float billAmount;
            double output; 
            String output1;

            percentageInp = Float.parseFloat(myEditField.getText().toString());
            billAmount = Float.parseFloat(myEditField2.getText().toString());

            percentage = ((float)percentageInp /100);

            output = (double)(billAmount * percentage);

            double result = output * 100;
            result = Math.round(result);
            result = result / 100;

            output1 = Double.toString(result);

            textView.setText(output1);

        }
    });
}
}

manifest.xml ...

清单.xml ...

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tip.calculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:debuggable="true">
        <activity
            android:name=".TipCalculator"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

here is my strings.xml

这是我的strings.xml

<resources>

    <string name="app_name">Tip Calculator</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

</resources>

回答by Niko Adrianus Yuwono

change the label

更改标签

android:label="Tip Calculator"

android:label="提示计算器"

or change your strings.xml

或更改您的 strings.xml

<string name="app_name">Tip Calculator</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">Tip Calculator</string>

回答by ssrp

This is because android does not allow for two different labels for the app_name and main activity name. But in case you want to use two different labels at the same time you could accomplish it as follow;

这是因为 android 不允许 app_name 和主要活动名称有两个不同的标签。但如果你想同时使用两个不同的标签,你可以按如下方式完成;

The name for your App to be shown on app menu

要在应用菜单上显示的应用名称

<application> android:lable = "@string/app_name" </application>

And the different label when you launch the activity;

以及启动活动时的不同标签;

in your onCreate() method of the main activity put;

在主要活动的 onCreate() 方法中;

this.setTitle("Your Title for the Activity");

回答by eoghanm

Thats just an error in eclipse sometimes, close eclipse then clean your project and it should be fine

有时这只是 eclipse 中的一个错误,关闭 eclipse 然后清理你的项目,它应该没问题