Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
HBHAndroid
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨秀秀
HBHAndroid
Commits
2e38cc75
Commit
2e38cc75
authored
Apr 15, 2025
by
小费同学阿
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基础搭建
功能开发 1:我的停车
parent
e3fb10c5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
308 additions
and
14 deletions
+308
-14
MyParkAddActivity.java
...in/java/com/xx/hbhconsumer/ui/park/MyParkAddActivity.java
+86
-1
MyParkAddViewModel.java
...n/java/com/xx/hbhconsumer/ui/park/MyParkAddViewModel.java
+14
-7
custom_cursor.xml
consumer/src/main/res/drawable/custom_cursor.xml
+5
-0
dot_circle.xml
consumer/src/main/res/drawable/dot_circle.xml
+8
-0
edit_text_default.xml
consumer/src/main/res/drawable/edit_text_default.xml
+9
-0
edit_text_filled.xml
consumer/src/main/res/drawable/edit_text_filled.xml
+6
-0
edit_text_focused.xml
consumer/src/main/res/drawable/edit_text_focused.xml
+9
-0
park_save_button_background.xml
...mer/src/main/res/drawable/park_save_button_background.xml
+5
-0
activity_my_park_add.xml
consumer/src/main/res/layout/activity_my_park_add.xml
+166
-6
No files found.
consumer/src/main/java/com/xx/hbhconsumer/ui/park/MyParkAddActivity.java
View file @
2e38cc75
package
com
.
xx
.
hbhconsumer
.
ui
.
park
;
import
android.os.Bundle
;
import
android.text.Editable
;
import
android.text.TextWatcher
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
...
...
@@ -10,7 +14,6 @@ import com.google.android.material.tabs.TabLayout;
import
com.google.android.material.tabs.TabLayout.OnTabSelectedListener
;
import
com.xx.hbhconsumer.BR
;
import
com.xx.hbhconsumer.R
;
import
com.xx.hbhconsumer.data.http.requst.LoginRequest
;
import
com.xx.hbhconsumer.data.http.requst.ParkRequest
;
import
com.xx.hbhconsumer.databinding.ActivityMyParkAddBinding
;
...
...
@@ -32,6 +35,72 @@ public class MyParkAddActivity extends BaseActivity<ActivityMyParkAddBinding, My
// 初始化 TabLayout
tabLayout
=
findViewById
(
R
.
id
.
tabLayout
);
// 初始化新增车牌号输入框,设置样式
EditText
[]
editTexts
=
new
EditText
[]{
findViewById
(
R
.
id
.
editText1
),
findViewById
(
R
.
id
.
editText2
),
findViewById
(
R
.
id
.
editText3
),
findViewById
(
R
.
id
.
editText4
),
findViewById
(
R
.
id
.
editText5
),
findViewById
(
R
.
id
.
editText6
),
findViewById
(
R
.
id
.
editText7
)
};
// 设置输入框的焦点变化和文本变化监听器
for
(
int
i
=
0
;
i
<
editTexts
.
length
;
i
++)
{
final
int
index
=
i
;
// 当前输入框的索引
EditText
editText
=
editTexts
[
i
];
editText
.
setOnFocusChangeListener
(
new
View
.
OnFocusChangeListener
()
{
@Override
public
void
onFocusChange
(
View
v
,
boolean
hasFocus
)
{
if
(
hasFocus
)
{
// 如果当前输入框获得焦点且内容为空,设置为“没有输入但点击了”的样式
if
(
editText
.
getText
().
toString
().
isEmpty
())
{
editText
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
edit_text_focused
));
}
editText
.
setCursorVisible
(
true
);
// 显示光标
}
else
{
// 如果当前输入框失去焦点且内容为空,恢复默认样式
if
(
editText
.
getText
().
toString
().
isEmpty
())
{
editText
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
edit_text_default
));
}
editText
.
setCursorVisible
(
false
);
// 隐藏光标
}
}
});
editText
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
}
@Override
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
}
@Override
public
void
afterTextChanged
(
Editable
s
)
{
if
(
s
.
toString
().
length
()
==
1
)
{
// 如果当前输入框已满且不是最后一个输入框,则跳转到下一个输入框
if
(
index
<
editTexts
.
length
-
1
)
{
editTexts
[
index
+
1
].
requestFocus
();
}
}
// 如果输入框内容被删除且当前输入框有焦点,设置为“没有输入但点击了”的样式
if
(
s
.
toString
().
isEmpty
()
&&
editText
.
isFocused
())
{
editText
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
edit_text_focused
));
}
else
if
(
s
.
toString
().
isEmpty
()
&&
!
editText
.
isFocused
())
{
// 如果输入框内容为空且没有焦点,恢复默认样式
editText
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
edit_text_default
));
}
else
{
// 如果输入框有内容,设置为已填充样式
editText
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
edit_text_filled
));
}
}
});
}
// 添加 Tab
for
(
String
tab
:
tabs
)
{
tabLayout
.
addTab
(
tabLayout
.
newTab
().
setText
(
tab
));
...
...
@@ -43,6 +112,7 @@ public class MyParkAddActivity extends BaseActivity<ActivityMyParkAddBinding, My
public
void
onTabSelected
(
TabLayout
.
Tab
tab
)
{
// 当 Tab 被选中时,通过 Toast 回显
Toast
.
makeText
(
MyParkAddActivity
.
this
,
"选中了:"
+
tab
.
getText
(),
Toast
.
LENGTH_SHORT
).
show
();
// 看选择哪个校验不一样
}
@Override
...
...
@@ -55,6 +125,21 @@ public class MyParkAddActivity extends BaseActivity<ActivityMyParkAddBinding, My
// 当 Tab 被重新选中时,不做处理
}
});
// 设置保存按钮的点击事件
binding
.
saveButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
// 获取每个输入框的内容
StringBuilder
combinedString
=
new
StringBuilder
();
for
(
EditText
editText
:
editTexts
)
{
combinedString
.
append
(
editText
.
getText
().
toString
());
}
// 将拼接后的字符串传递给 ViewModel
viewModel
.
saveCombinedString
(
combinedString
.
toString
());
}
});
}
@Override
...
...
consumer/src/main/java/com/xx/hbhconsumer/ui/park/MyParkAddViewModel.java
View file @
2e38cc75
package
com
.
xx
.
hbhconsumer
.
ui
.
park
;
import
android.app.Application
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.databinding.ObservableField
;
import
androidx.lifecycle.MutableLiveData
;
import
com.xx.hbhconsumer.data.http.requst.LoginRequest
;
import
com.xx.hbhconsumer.data.http.requst.ParkRequest
;
import
me.goldze.mvvmhabit.base.BaseViewModel
;
import
me.goldze.mvvmhabit.binding.command.BindingAction
;
import
me.goldze.mvvmhabit.binding.command.BindingCommand
;
public
class
MyParkAddViewModel
extends
BaseViewModel
<
ParkRequest
>
{
// 添加一个方法来接收拼接后的字符串
public
void
saveCombinedString
(
String
combinedString
)
{
// 在这里处理拼接后的字符串
// 例如:保存到数据库或进行其他逻辑处理
Toast
.
makeText
(
getApplication
().
getApplicationContext
(),
"保存的字符串: "
+
combinedString
,
Toast
.
LENGTH_SHORT
).
show
();
}
public
MyParkAddViewModel
(
@NonNull
Application
application
,
ParkRequest
model
)
{
super
(
application
,
model
);
}
}
}
\ No newline at end of file
consumer/src/main/res/drawable/custom_cursor.xml
0 → 100644
View file @
2e38cc75
<!-- custom_cursor.xml -->
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<size
android:width=
"1dp"
/>
<!-- 设置光标的宽度 -->
<solid
android:color=
"#5971A4"
/>
<!-- 设置光标的颜色 -->
</shape>
\ No newline at end of file
consumer/src/main/res/drawable/dot_circle.xml
0 → 100644
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<size
android:width=
"10dp"
android:height=
"10dp"
/>
<solid
android:color=
"#757575"
/>
<corners
android:radius=
"25dp"
/>
</shape>
\ No newline at end of file
consumer/src/main/res/drawable/edit_text_default.xml
0 → 100644
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"#FFFFFF"
/>
<stroke
android:width=
"1dp"
android:color=
"#dde4f2"
/>
<corners
android:radius=
"4dp"
/>
</shape>
\ No newline at end of file
consumer/src/main/res/drawable/edit_text_filled.xml
0 → 100644
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"#dde4f2"
/>
<corners
android:radius=
"4dp"
/>
</shape>
\ No newline at end of file
consumer/src/main/res/drawable/edit_text_focused.xml
0 → 100644
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"#FFFFFF"
/>
<stroke
android:width=
"1dp"
android:color=
"#5971a4"
/>
<corners
android:radius=
"4dp"
/>
</shape>
\ No newline at end of file
consumer/src/main/res/drawable/park_save_button_background.xml
0 → 100644
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<solid
android:color=
"#5971A4"
/>
<corners
android:radius=
"40dp"
/>
</shape>
\ No newline at end of file
consumer/src/main/res/layout/activity_my_park_add.xml
View file @
2e38cc75
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:binding=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
...
...
@@ -27,7 +28,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"40dp"
android:layout_below=
"@id/bar"
android:
background=
"@color/white
"
android:
paddingTop=
"7dp
"
android:paddingBottom=
"7dp"
app:tabBackground=
"@null"
app:tabGravity=
"fill"
...
...
@@ -42,14 +43,173 @@
app:tabTextColor=
"@color/black"
>
</com.google.android.material.tabs.TabLayout>
<!--
输入车牌号
-->
<!--
输入车牌号
-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/viewPager"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_below=
"@id/tabLayout"
>
android:layout_height=
"wrap_content"
android:layout_below=
"@id/tabLayout"
android:background=
"#ffffff"
android:paddingTop=
"20dp"
android:paddingBottom=
"20dp"
android:paddingLeft=
"6dp"
android:paddingRight=
"6dp"
android:layout_marginTop=
"10dp"
>
<!-- 输入框1 -->
<EditText
android:id=
"@+id/editText1"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toLeftOf=
"@id/editText2"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 输入框2 -->
<EditText
android:id=
"@+id/editText2"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textStyle=
"bold"
android:textCursorDrawable=
"@drawable/custom_cursor"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/editText1"
app:layout_constraintRight_toLeftOf=
"@id/dotView"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 黑色点点 -->
<View
android:id=
"@+id/dotView"
android:layout_width=
"4dp"
android:layout_height=
"4dp"
android:background=
"@drawable/dot_circle"
app:layout_constraintBottom_toBottomOf=
"@id/editText2"
app:layout_constraintLeft_toRightOf=
"@id/editText2"
app:layout_constraintRight_toLeftOf=
"@id/editText3"
app:layout_constraintTop_toTopOf=
"@id/editText2"
/>
<!-- 输入框3 -->
<EditText
android:id=
"@+id/editText3"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/dotView"
app:layout_constraintRight_toLeftOf=
"@id/editText4"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 输入框4 -->
<EditText
android:id=
"@+id/editText4"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/editText3"
app:layout_constraintRight_toLeftOf=
"@id/editText5"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 输入框5 -->
<EditText
android:id=
"@+id/editText5"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/editText4"
app:layout_constraintRight_toLeftOf=
"@id/editText6"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 输入框6 -->
<EditText
android:id=
"@+id/editText6"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/editText5"
app:layout_constraintRight_toLeftOf=
"@id/editText7"
app:layout_constraintTop_toTopOf=
"parent"
/>
<!-- 输入框7 -->
<EditText
android:id=
"@+id/editText7"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:textCursorDrawable=
"@drawable/custom_cursor"
android:background=
"@drawable/edit_text_default"
android:gravity=
"center"
android:inputType=
"text"
android:maxLength=
"1"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toRightOf=
"@id/editText6"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- 保存按钮 -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/viewPager"
android:layout_marginTop=
"2dp"
android:background=
"#ffffff"
>
<Button
android:id=
"@+id/saveButton"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"75dp"
android:layout_marginTop=
"20dp"
android:layout_marginBottom=
"20dp"
android:layout_marginRight=
"75dp"
android:background=
"@drawable/park_save_button_background"
android:text=
"保存"
android:textColor=
"#FFFFFF"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment