Android:简易的单词本(一)
博客专区 > ForevrA 的博客 > 博客详情
Android:简易的单词本(一)
ForevrA 发表于4年前
Android:简易的单词本(一)
  • 发表于 4年前
  • 阅读 201
  • 收藏 3
  • 点赞 0
  • 评论 0

【腾讯云】新注册用户域名抢购1元起>>>   

摘要: 新手上路,请多指教

先来看布局文件(好多人只是发核心代码,这让某些刚刚学习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>


  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 1
博文 3
码字总数 2486
×
ForevrA
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: