[英]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.