简体   繁体   English

我在Eclipse中制作了一个android应用。 现在我要更改默认布局

[英]I have made a android app in Eclipse. Now I want to change the Default layout

I have set the layout Test into my app 我已将版式测试设置为我的应用

<activity
            android:name="com.example.test.TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

When I run it it's not take the testactivity. 当我运行它时,不需要进行测试。 I have run (Run as app) many time. 我已经运行了很多次(作为应用程序运行)。 it's take MainActivity. 这需要MainActivity。 Do someone know how to modified it. 有人知道如何修改它。

if this is need to somewhere please tell me. 如果需要在某个地方,请告诉我。 What I want is now change the app to run the Testactivity instead of MainActivity 我现在想要的是更改应用程序以运行Testactivity而不是MainActivity

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".TestActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="36dp"
        android:layout_marginTop="152dp" android:onClick="btnTest"
        android:text="Button" />


</RelativeLayout>

Activity: 活动:

public class TestActivity extends Activity {

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


    public ArrayList<String> GetArray(String input){
        ArrayList<String> arr=  new ArrayList<String>();

        return arr;
    }
    public void btnTest(View view){
        Toast.makeText(getApplicationContext(), "This is test", Toast.LENGTH_SHORT);
    }
}

在覆盖的onCreate() ,提及您的test_activity xml文件而不是主Activity.xml文件。

setContentView(R.layout.test_activity);

your problem is that you have setted the same layout for both of your activities . 您的问题是您为两个活动都设置了相同的布局。

in your Activity TestActivity , in the onCreate() method ;you should set the content view like this : 在您的Activity TestActivity ,在onCreate()方法中;您应该这样设置内容视图:

setContentView(R.layout.test_activity);

instead of : 代替 :

setContentView(R.layout.activity_main);

If you just want to change the content XML file just change the 如果您只想更改内容XML文件,只需更改

setContentView(R.layout.test_activity);

in the onCreate() method. 在onCreate()方法中。

If you want 2 activites then you need to add this 如果您需要2个活动,则需要添加此活动

<activity
    android:name="com.example.test.TestActivity"
    android:label="@string/app_name" >
</activity>

to your manifest and a new java class to run the activity and change to the new activity with an intent. 清单和一个新的Java类来运行活动,并有意地更改为新活动。

Intent i = new Intent(activity_main.this, TestActivity.class);
startActivity(i);

Try this... Eclipse => Project-> Clean 试试这个... Eclipse => Project-> Clean

change the content view in onCreate() just change the 在onCreate()中更改内容视图,只需更改

setContentView(R.layout.test);

And change it in your Manifest file: 并在清单文件中进行更改:

<activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

暂无
暂无

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

相关问题 通过Eclipse在物理Android设备上安装了HelloWorld应用。 我如何在电话上找到它? - Installed HelloWorld app on physical Android device through Eclipse. How do I find it on phone? Android和Eclipse。 我必须在我的应用中包含服务代码吗? 多个应用使用相同的服务 - Android and Eclipse. Must I include service code in my app? Multiple apps are using the same service 日食。 无法使用Android版式编辑器打开 - Eclipse. Can not open with Android Layout Editor 我有一个连接到phpmyadmin的laravel网站,但现在我想将android应用程序连接到同一数据库 - I have a laravel website that is connected to phpmyadmin but now I want to connect android app to same database Android 仿真器未反映我在.xml 布局文件中所做的更改 - The Android emulator is not reflecting changes I have made in .xml layout file 我已经从API的JSON格式中获取了文本,现在我想从我的android应用中的同一API向其添加图像 - I have taken text from JSON format of an API now I want to add image to it from same API in my android app 我已经制作了一个使用Google地图的应用程序,现在可以在不破坏版权的情况下将其加载到Google Play上吗? - I have made an app that uses google maps can I now load it on to google play without breaking copyright? 我有在模拟器中编译的android应用程序,现在怎么办? - I have my android app compiling in an emulator, now what? 当我将默认xml布局文件更改为另一个时,Android应用程序崩溃 - Android app crashes when I change the default xml layout file to another android eclipse图形布局错误...我必须重新启动 - android eclipse graphical layout bugs…do i have to restart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM