[安卓] 数据库为Android - P2创建接口
在以前的 [安卓] 数据库的Android仲 - P1涛数据库 我已经引导你创建数据库. 本文中,我将指导您 风格材料设计应用程序的创造者.
注意:
这个系列的剧本我会用英文写. 然而,这是我的英文写作风格“译自越南”那么你会很容易跟进.
这里: Android的工作室 1.2.2
Android的SDK 5.1.1
闵SDK: 4.0 (安卓 4.0 以上将被用于应用程序)
但是,你绝对可以做Eclipse和Android的下
在他的应用程序将使用RecyclerView, CardView. 你应该多看,如果不明确这件事:
RecyclerView Android中
CardView Android中
步 1: 应用程序配置
下面是一些需要配置用于创建应用程序.
首先,我们需要在配置文件中的应用 build.gradle 要使用的 支持设计库, recyclerview, cardview 部分依赖
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
接下来是文件的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cachhoc.net.tut.demodatabase" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NoteActivity"
android:label="@string/title_activity_note" >
</activity>
</application>
</manifest>
我们有 2 活动, 一个包含笔记列表MainActivity, 一个是NoteActivity起草笔记.
你有没有在应用程序的主题是发现 @风格/ AppTheme, 你打开文件 RES /价值/ style.xml 和编辑主题的主题材料.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="android:textColor">@color/text_primary</item>
<item name="colorAccent">@color/primary</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/primary</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:background">@color/white</item>
</style>
</resources>
你有没有注意到,我们有 1 风格Là AppCompatAlertDialogStyle 时间删除笔记,主题对话框提示是否删除或不.
我们还需要有文件 string.xml 和 colors.xml (在 RES /价值/) 包含字符串和颜色的应用. 如果没有,然后单击以选中新 … 创建文件.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#4CAF50</color>
<color name="text_primary">#000000</color>
<color name="primary_dark">#388E3C</color>
<color name="accent">#FF4081</color>
<color name="white">#FFFFFF</color>
<color name="color_item_press">#81C784</color>
</resources>
<resources>
<string name="app_name">My Note</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="add">Add</string>
<string name="delete">Delete</string>
<string name="save">Save</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<!-- -->
<string name="title_note">Title note</string>
<string name="content">Content</string>
<string name="title_activity_note">Create Note</string>
</resources>
此外,我们还需要他们ic_add, ic_save, ic_delete, ic_launcher的应用程序, 而且很容易,我们可以创建和搜索 Android的资产工作室 或见 在Android的资产Studio中创建图标说明 如果你不明确.
我们正在做这项工作的应用程序配置.
步 2: 接口设计
设计的主要活性的研究
首先是activity_main, 包括 RecyclerView 包含笔记列表, 和 1 浮法操作按钮 做笔记.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_note"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_add"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</RelativeLayout>
你有没有注意到,当创建FloatingActionButton要求 应用程序:边框宽度=”0DP” 否则机器会显示一些是方形的,不是圆的.
FloatingActionButton的颜色 colorAccent 在style.xml定义的主题文件. 您也可以通过设置背景更改.
列表中的设计项
接下来,我们需要创建的皮肤 1 列表中的项目. 它将包括 2 标题和内容系 (标题和笔记内容). Chúng sẽ được đặt trong CardView để có giao diện đẹp hơn 🙂

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
card_view:cardCornerRadius="1dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/backgroud_item_note"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="1"
android:text="@string/title_note"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="1"
android:text="@string/content"
android:textSize="13sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
机器人:线=”1″ 和 机器人:椭圆=”比” 只有帮助每个项目 1 标题行和 1 在线内容. 如果标题或内容,将削减长,多余的空格 3 背后点.
我们需要创建文件 backgroud_item_note.xml 在 RES /绘制/ 背景资料狗. 点击时没有点击,当它允许对项目的背景颜色.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/color_item_press" android:state_pressed="true"/>
<item android:drawable="@color/white" android:state_pressed="false"/>
</selector>
接口设计制图笔记
最后,我们写条子的时候需要设计界面. 该接口将包括 2 的EditText的标题和内容.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<EditText
android:id="@+id/edit_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center_vertical"
android:hint="@string/title_note"
android:padding="5dp"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/edit_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="start"
android:hint="@string/content"
android:padding="5dp"
android:textSize="18sp" />
</LinearLayout>
另外我们也有 2 删除和保存菜单设计文件 RES /菜单/ menu_note.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_delete"
android:icon="@drawable/ic_delete"
android:orderInCategory="100"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/menu_save"
android:icon="@drawable/ic_save"
android:orderInCategory="100"
android:title="@string/save"
app:showAsAction="always" />
</menu>
部分 2 仅这一点就创建可引导您和编码Java接口完美似乎总是来这里,而且长期来看也有点累了手Java代码将部分会合这样一部分 3 NHE.
在本教程的帖子 数据库的Android仲 由 nguyenvanquan7826



他的E问的是如何给floatingactionbutton在 1 碎片 ? 代码仲片段
公共类AddNoteFragment扩展片段{
@覆盖
公众查看onCreateView(LayoutInflater气筒, 的ViewGroup集装箱, 捆绑savedInstanceState) {
查看viewAddNote = inflater.inflate(R.layout.fragment_main_add_note, 空值);
返回viewAddNote ;
}
}
误 :
android.view.InflateException: 二进制XML文件行 #11: 错误充气类android.support.design.widget.FloatingActionButton在android.view.LayoutInflater.createView(LayoutInflater.java:633)
你给Fab片段对应于DJK XML代码.
E要正确的,一直没有 .. 他可能没有吧为电子Teamview他 ….
您联系FB / nguyenvanquan7826 NHE
如果你还没有接触fb.com/nguyenvanquan7826 DJK NHE.