App Name是Eclipse MainActivity?

时间:2012-07-24 16:59:46

标签: android eclipse android-layout android-emulator android-activity

我已经完成了小费计算器应用,但是当我运行它时,名称为MainActivity,我不知道如何更改它,我尝试编辑strings.xml但是当我运行应用时我收到错误,我不知道还有什么可以尝试,我可以做些什么来改变它以便它出现在模拟器上

在strings.xml上......

名:title_activity_main 值:MainActivity

这里也是我的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 ...

<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>

这是我的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>

3 个答案:

答案 0 :(得分:4)

更改标签

  

android:label =“小费计算器”

或更改您的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>

答案 1 :(得分:3)

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

应用程序菜单上显示的应用程序名称

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

启动活动时的不同标签;

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

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

答案 2 :(得分:0)

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