其他分享
首页 > 其他分享> > 安卓——家庭记账本2

安卓——家庭记账本2

作者:互联网

今天将安卓系统的自定义软键盘和各个基本页面完成了,键盘的颜色、样式...需要自己配置

首先,完成页面必须要有图标,我的图标是在阿里的矢量图库中下载的

https://www.iconfont.cn/

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@color/white">
    <TextView
        android:id="@+id/dialog_beizhu_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_remark"
        android:textSize="16sp"
        android:textColor="@color/black"/>
    <EditText
        android:id="@+id/dialog_beizhu_et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/dialog_beizhu_tv"
        android:hint="@string/remark"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        android:textSize="14sp"
        android:background="@color/white">
        <requestFocus/>
    </EditText>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/dialog_beizhu_et"
        android:padding="10dp">
        <Button
            android:id="@+id/dialog_beizhu_btn_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/cancel"
            android:background="@drawable/dialog_btn_bg"
            android:textStyle="bold"
            android:textColor="@color/green_006400"
            android:layout_marginRight="5dp"/>
        <Button
            android:id="@+id/dialog_beizhu_btn_ensure"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/ensure"
            android:background="@drawable/main_record_bg"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:layout_marginRight="5dp"/>
    </LinearLayout>

</RelativeLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/white">
    <DatePicker
        android:id="@+id/dialog_time_dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/input_time"
        android:padding="10dp"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp">
        <EditText
            android:id="@+id/dialog_time_et_hour"
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" : "
            android:textSize="20dp"
            android:textStyle="bold"/>
        <EditText
            android:id="@+id/dialog_time_et_minute"
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="2"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:orientation="horizontal">
        <Button
            android:id="@+id/dialog_time_btn_cancel"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:text="@string/cancel"
            android:textColor="@color/green_006400"
            android:background="@null"
            android:layout_marginRight="20dp"/>
        <Button
            android:id="@+id/dialog_time_btn_ensure"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:text="@string/ensure"
            android:textColor="@color/green_006400"
            android:background="@null"
            android:layout_marginRight="20dp"/>
    </LinearLayout>

</LinearLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<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="@color/grey_f3f3f3">

    <RelativeLayout
        android:id="@+id/frag_record_r1_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="10dp">
        <ImageView
            android:id="@+id/frag_record_iv"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@mipmap/ic_qita_fs"/>
        <TextView
            android:id="@+id/frag_record_tv_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="其他"
            android:layout_toRightOf="@id/frag_record_iv"
            android:layout_centerVertical="true"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_marginLeft="10dp"/>
        <EditText
            android:id="@+id/frag_record_et_money"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:inputType="number"
            android:background="@color/white"/>
    </RelativeLayout>
    <View
        android:id="@+id/frag_record_line1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/frag_record_r1_top"
        android:background="@color/grey_f3f3f3"/>
    <GridView
        android:id="@+id/frag_record_gv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/frag_record_line1"
        android:background="@color/white"
        android:numColumns="5"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"/>
<!--    自定义软键盘-->
    <android.inputmethodservice.KeyboardView
        android:id="@+id/frag_record_keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:keyBackground="@color/grey_f3f3f3"
        android:keyTextColor="@color/black"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:paddingTop="1dp"
        android:layout_alignParentBottom="true"
        android:shadowColor="@color/white"
        android:shadowRadius="0.0"/>
    <RelativeLayout
        android:layout_above="@id/frag_record_keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">
        <TextView
            android:id="@+id/frag_record_tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2021年8月29日 19:34"
            android:layout_alignParentRight="true"
            android:padding="10dp"/>
        <TextView
            android:id="@+id/frag_record_tv_beizhu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="添加备注"
            android:layout_toLeftOf="@id/frag_record_tv_time"
            android:padding="10dp"/>
    </RelativeLayout>

</RelativeLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:padding="10dp"
    android:background="@color/white">
    <ImageView
        android:id="@+id/item_mainlv_iv"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:src="@mipmap/ic_yanjiu_fs"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/item_mainlv_iv"
        android:layout_marginLeft="10dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/item_mainlv_tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="烟酒茶"
            android:textStyle="bold"
            android:textSize="16sp"/>
        <TextView
            android:id="@+id/item_mainlv_tv_beizhu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="中华"
            android:layout_marginTop="5dp"
            android:textSize="12sp"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="vertical">
        <TextView
            android:id="@+id/item_mainlv_tv_money"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="¥ 30.0"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/item_mainlv_tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="今天"
            android:layout_marginTop="5dp" />
    </LinearLayout>

</RelativeLayout>

 

 

<?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_height="match_parent"
    android:background="@color/grey_f3f3f3">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:padding="20dp">
    <TextView
        android:id="@+id/item_mainlv_top_tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/month_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_out"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥ 0"
        android:layout_below="@id/item_mainlv_top_tv1"
        android:textSize="25sp"
        android:textStyle="bold"
        android:textColor="@color/black"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"/>
    <ImageView
        android:id="@+id/item_mainlv_top_iv_hide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@mipmap/ih_show"
        android:layout_alignTop="@id/item_mainlv_top_tv_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/month_in"
        android:layout_below="@id/item_mainlv_top_tv_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_in"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:text="¥ 0"
        android:layout_below="@id/item_mainlv_top_tv_out"
        android:layout_toRightOf="@id/item_mainlv_top_tv2"
        android:layout_marginLeft="3dp"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_budget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥ 0"
        android:textColor="@color/black"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@id/item_mainlv_top_tv2"
        android:layout_marginLeft="5dp"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/budget"
        android:layout_toLeftOf="@id/item_mainlv_top_tv_budget"
        android:layout_alignBottom="@id/item_mainlv_top_tv2"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@mipmap/ih_biaoge"
        android:layout_below="@id/item_mainlv_top_tv2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="@string/table"
        android:textColor="@color/green_006400"
        android:drawablePadding="10dp"/>
</RelativeLayout>
    <TextView
        android:id="@+id/item_mainlv_top_tv_day"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="今日支出 ¥0 收入 ¥0"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"/>
</LinearLayout>

 

 

<?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_height="wrap_content"
    android:padding="5dp">
    <ImageView
        android:id="@+id/item_recordfrag_iv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_qita_fs"/>
    <TextView
        android:id="@+id/item_recordfrag_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="其他"
        android:layout_marginTop="5dp"
        android:textSize="12sp"
        android:textColor="@color/grey_7d7d7d"
        android:gravity="center"/>

</LinearLayout>

 

 

package com.example.bookeep.utils;

import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.Editable;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;

import com.example.bookeep.R;

public class KeyBoardUtils {
    private final Keyboard k1;
    private KeyboardView keyboardView;
    private EditText editText;

    public interface OnEnsureListener{
        public  void onEnsure();
    }
    OnEnsureListener onEnsureListener;

    public void setOnEnsureListener(OnEnsureListener onEnsureListener) {
        this.onEnsureListener = onEnsureListener;
    }

    public KeyBoardUtils(KeyboardView keyboardView, EditText editText) {
        this.keyboardView = keyboardView;
        this.editText = editText;
        this.editText.setInputType(InputType.TYPE_NULL);//取消系统键盘
        k1=new Keyboard(this.editText.getContext(), R.xml.key);

        this.keyboardView.setKeyboard(k1);
        this.keyboardView.setEnabled(true);
        this.keyboardView.setPreviewEnabled(false);
        this.keyboardView.setOnKeyboardActionListener(listener);//设置监听
    }

    KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() {
        @Override
        public void onPress(int i) {

        }

        @Override
        public void onRelease(int i) {

        }

        @Override
        public void onKey(int i, int[] ints) {
            Editable editable=editText.getText();
            int start = editText.getSelectionStart();
            switch (i){
                case Keyboard.KEYCODE_DELETE://点击删除键
                    if(editable!=null&&editable.length()>0){
                        if (start>0){
                            editable.delete(start-1,start);
                        }
                    }
                    break;
                case Keyboard.KEYCODE_CANCEL://点击清零
                    editable.clear();
                    break;
                case Keyboard.KEYCODE_DONE://点击完成
                    onEnsureListener.onEnsure();
                    break;
                default:editable.insert(start,Character.toString((char)i));
                    break;
            }
        }

    };
    //显示键盘
    public void showKey(){
        int visibility=keyboardView.getVisibility();
        if(visibility== View.INVISIBLE||visibility==View.GONE){
            keyboardView.setVisibility(View.VISIBLE);
        }
    }

    //隐藏键盘
    public void hideKey(){
        int visibility=keyboardView.getVisibility();
        if(visibility== View.INVISIBLE||visibility==View.INVISIBLE){
            keyboardView.setVisibility(View.GONE);
        }
    }
}

明天开始将会建立数据库,并开始后台代码的书写。

标签:int,editText,安卓,keyboardView,家庭,记账,void,import,public
来源: https://www.cnblogs.com/jzz-111jy/p/15859800.html