目录
新建工程(Android Studio)
略。
添加、编辑资源文件
- 编辑
res
->values
->strings.xml
文件,内容如下:
<resources>
<string name="app_name">MyNoteBook</string>
<string name="title">记事本</string>
<string name="btn_confirm">确定</string>
<string name="btn_cancel">取消</string>
<string name="btn_add">添加</string>
<string name="btn_save">保存</string>
<string name="btn_return">返回</string>
<string name="save_succ">保存成功!</string>
<string name="save_fail">保存失败!标题或内容不能为空!</string>
</resources>
- 在
res
->drawable
目录下添加shape.xml
文件用于实现按钮的圆角效果,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#1C82C4"/>
<!-- android:radius 按钮四角弧形的半径 -->
<corners android:radius="8dip" />
<!-- padding:Button里面的文字与Button边界的内边距 -->
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
- 编辑
res
->values
->style.xml
文件,在其中定义全屏风格
,美化界面。内容如下:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="FullTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
- 在
AndroidManifest.xml
文件中应用全屏风格
。更改application元素
的android:theme
属性即可。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zys.mynotebook">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/FullTheme">
<activity android:name=".EditActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
- 更改程序图标。
略。
新建一个Activity,EditActivity作为笔记编辑、浏览界面
先保留自动生成的布局文件activity_edit.xml
文件。
编辑、添加布局文件
- 编辑
res
->layout
路径下的主界面布局文件activity_main.xml
,主要利用ListView
来显示所有笔记的标题和事件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#03AEDA"
android:orientation="horizontal">
<!-- 图标-->
<ImageView
android:src="@drawable/note_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="2dp"/>
<TextView
android:id="@+id/music_list_title"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginBottom="6dp"
android:text="@string/title"
android:textSize="16dp"
android:textColor="#FFFFFF"
android:paddingLeft="10dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="2dp">
<Button
android:id="@+id/btn_add"
android:layout_width="50dp"
android:layout_height="40dp"
android:text="@string/btn_add"
android:background="@drawable/shape"
android:textColor="#B9E3FD"
android:layout_gravity="right"
android:layout_marginRight="8dp"
android:layout_marginTop="2dp" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/note_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
- 添加在
res
->layout
目录下添加布局文件item_layout.xml
文件,作为主界面中ListView
的每个item
的布局,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:padding="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/rand_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="2dp"
android:layout_margin="4dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height=