1.新建类继承Activity或其子类,现在一般继承AppCompatActivity
public class TestActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); }}
2.在AndroidManifest文件中声明这个activity
<activity android:name=".TestActivity"></activity>
3.创建layout布局文件并在activity中的onCreate中设置
public class TestActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); }} 在AndroidManifest中设置启动activity
<activity android:name=".HelloWorldActivity" android:label="lidahua" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity> 不适用系统自带的titlebar
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <activity android:name=".HelloWorldActivity" android:label="lidahua" --给titlebar重新设置标题 > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TestActivity"> </activity> </application> </manifest>
原文地址:https://www.cnblogs.com/AppTester/p/9937679.html
时间: 2024-10-15 10:09:51