Android:简易的单词本(一)

先来看布局文件(好多人只是发核心代码,这让某些刚刚学习andriod的同学很是不爽,想要运行结果,总是缺点什么。所以我先把布局文件列出来......)

activity_main.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="#CCCCCC"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout 
        android:layout_marginTop="50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        
        <Button 
            style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/insert"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:background="@drawable/shape" />
        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/search"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:background="@drawable/shape" />
        <Button 
            style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/delete"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:background="@drawable/shape" />
        
    </LinearLayout>
    
    <RelativeLayout 
        android:layout_marginTop="200dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        
        <EditText 
            android:id="@+id/word"
            android:background="@drawable/edittextshape"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:padding="3dp"
            android:inputType="textUri"
            android:hint="@string/word" />

        <ImageButton
            android:id="@+id/clear1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/clear"
            android:src="@drawable/clear"
            android:visibility="visible" />
        
    </RelativeLayout>
    <RelativeLayout 
        android:layout_marginTop="300dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">        
        <EditText 
            android:inputType="text"
            android:id="@+id/detail"
            android:background="@drawable/edittextshape"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:padding="3dp"
            android:hint="@string/detail"
            android:textColorHint="#AAAAAA" />        
        <ImageButton
            android:id="@+id/clear2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/clear"
            android:src="@drawable/clear"
            android:visibility="visible" />
        
    </RelativeLayout>
    <RelativeLayout 
        android:layout_marginTop="400dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">        
        <EditText 
            android:background="@drawable/edittextshape"
            android:inputType="textUri"
            android:id="@+id/search_edittext"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:padding="3dp"
            android:hint="@string/search" />
        
        <ImageButton
            android:id="@+id/clear3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/clear"
            android:src="@drawable/clear"
            android:visibility="visible" />        
    </RelativeLayout>
</RelativeLayout>

result.xml,用于显示搜索结果:

<?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="match_parent"
    android:orientation="vertical" >    
    <ListView 
        android:id="@+id/show"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#0099CC"
        android:dividerHeight="2dp">
    </ListView>
</LinearLayout>

line.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <LinearLayout 
        android:layout_marginTop="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/words"
            android:layout_gravity="center_vertical" />
        <TextView 
            android:id="@+id/word_list"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:textSize="16sp"
            android:padding="10dp" 
            android:background="#FFFFFF"
            android:layout_gravity="center_vertical"
            android:textColor="#000000"
            android:inputType="none" />
    </LinearLayout>
    
     <LinearLayout 
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/explain" 
            android:layout_gravity="center_vertical" />
        <TextView 
            android:id="@+id/detail_list"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:textSize="16sp"
            android:background="#CCCCCC"
            android:layout_gravity="center_vertical"
            android:textColor="#000000"
            android:padding="10dp"
            android:inputType="none" />
        
    </LinearLayout>
</LinearLayout>

edit.xml,用于编辑单词:

<?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="match_parent"
    android:orientation="vertical"
    android:background="#FFFFFF" >
    
    
    <LinearLayout 
        android:layout_marginTop="5dp"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/words"
            android:layout_gravity="center_vertical" />

        <EditText
            android:id="@+id/word_list_edit"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:background="@drawable/edittextshape"
            android:inputType="textUri"
            android:padding="10dp"
            android:textColor="#000000"
            android:textSize="16sp" />
        
    </LinearLayout>
    
     <LinearLayout 
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/explain" 
            android:layout_gravity="center_vertical" />

        <EditText
            android:id="@+id/detail_list_edit"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:background="@drawable/edittextshape"
            android:inputType="text"
            android:padding="10dp"
            android:textColor="#000000"
            android:textSize="16sp" />
    </LinearLayout>
    
     <Button 
         android:id="@+id/positive"
         android:layout_width="60dp"
         android:layout_height="40dp"
         android:background="@drawable/shape"
         android:text="@string/positive"
         android:layout_gravity="center_horizontal" />

</LinearLayout>

各个控件的样式:

shape.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#FFFFCC" />
    <corners android:radius="10dp" />
    <stroke android:color="#CCFFFF" />
</shape>

edittextshape.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#FFFFFF"/>
    <corners android:radius="3dp"/>
    <stroke 
        android:width="1dp"
        android:color="#BDC7D8"/>
</shape>


value内的元素:

arrays.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="array">
        <item>编辑</item>
        <item>删除</item>
    </string-array> 
</resources>

string.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">单词本</string>
    <string name="action_settings">Settings</string>
    <string name="word">输入单词</string>
    <string name="detail">解释</string>
    <string name="search">搜索</string>
    <string name="words">单词:</string>
    <string name="explain">释义:</string>
    <string name="positive">确定</string>
    <string name="clear">清除</string>
</resources>


转载于:https://my.oschina.net/xiaoming2014/blog/224311

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值