今天的任务为创建UI fragment,详细代码如下:
strings.xml:
<resources> <string name="app_name">Criminallntent</string> <string name="crime_title_hint">Enter a title for the crime.</string> <string name="crime_title_label">Title</string> <string name="crime_details_label">Details</string> <string name="crime_solved_label">Solved</string> </resources>
fragment_crime.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_margin="16dp" android:layout_height="match_parent"> <TextView style="?android:listSeparatorTextViewStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/crime_title_label"/> <EditText android:id="@+id/crime_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/crime_title_hint"/> <TextView style="?android:listSeparatorTextViewStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/crime_details_label"/> <Button android:id="@+id/crime_date" android:layout_width="match_parent" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/crime_solved" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/crime_solved_label"/> </LinearLayout>
效果如下图所示: