我正在構建Android應用並創建了登錄屏幕。下一個屏幕將顯示登錄用戶的一組選項,他必須從中選擇一個。在Android應用中定義活動的佈局
第二項活動是從的onPostExecute
方法開始使用startActivity(intent)
代碼。
Intent intent = null;
intent = new Intent(context, DisplayMessageActivity.class);
context.startActivity(intent);
我想建立使用.xml文件activity_display_message.xml
此屏幕的UI。這個條目已經發送到清單文件。 我在這個.xml文件中指定的任何佈局屬性都沒有得到應用。任何在這方面的幫助,高度讚賞。例如使用下面的代碼,我無法獲得我設置的背景顏色。這對我的主要活動使用的.xml工作正常。
我DisplayMessageActivity類的onCreate功能
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intent intent = getIntent();
String message = intent.getStringExtra(CommonStaticValues.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
完整activity_display_message.xml
文件
<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:background="@color/background_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".DisplayMessageActivity" />
</RelativeLayout>
請爲DisplayMessageActivity和完整的佈局XML顯示onCreate。 – Simon
background_color是如何定義的? –
我有res /值下的colors.xml文件。這包含一個background_color的條目,很像strings.xml中的條目 –