Android activity建立三部曲
阿新 • • 發佈:2018-11-10
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>