Skip to content

Commit bdb81bc

Browse files
feat(lite): 重构键盘样式移除自定义键盘样式,改为并优化对话框布局
-使用MaterialComponents的TextButton - 更新对话框布局,调整按钮样式键盘按钮点击逻辑 - 更新主题和间距 - 在主界面添加KeyBoardView组件 - 优化样式,使用Base.Theme.AndroidLite.NoActionBar
1 parent e360d03 commit bdb81bc

19 files changed

Lines changed: 201 additions & 159 deletions

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:label="@string/app_name"
1818
android:roundIcon="@mipmap/ic_launcher_round"
1919
android:supportsRtl="true"
20-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
20+
android:theme="@style/Theme.AndroidLite.NoActionBar"
2121
android:usesCleartextTraffic="true">
2222
<activity
2323
android:name=".view.MainActivity"

app/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@
4646
android:layout_width="wrap_content"
4747
android:layout_height="wrap_content"
4848
android:layout_margin="@dimen/dp_10"
49-
android:text="按住录音"
50-
android:textColor="@color/black" />
49+
android:text="按住录音" />
5150

5251
<Button
5352
android:id="@+id/socketButton"
5453
android:layout_width="wrap_content"
5554
android:layout_height="wrap_content"
5655
android:layout_margin="@dimen/dp_10"
57-
android:text="连接"
58-
android:textColor="@color/black" />
56+
android:text="连接" />
57+
58+
<com.pengxh.androidx.lite.widget.KeyBoardView
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content" />
5961
</LinearLayout>
6062
</RelativeLayout>

app/src/main/res/values/themes.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<resources>
2+
<!-- Base application theme. -->
3+
<!-- android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"--> <!-- 圆方紫色按钮白字 -->
4+
<!-- android:theme="@style/Theme.AppCompat.Light.NoActionBar"--> <!-- 默认 -->
5+
<style name="Base.Theme.AndroidLite.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
6+
<!-- Customize your light theme here. -->
7+
</style>
8+
9+
<style name="Theme.AndroidLite.NoActionBar" parent="Base.Theme.AndroidLite.NoActionBar" />
10+
</resources>

lite/src/main/java/com/pengxh/androidx/lite/widget/KeyBoardView.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.pengxh.androidx.lite.widget;
22

33
import android.content.Context;
4-
import android.text.TextUtils;
54
import android.util.AttributeSet;
5+
import android.util.Log;
66
import android.view.KeyEvent;
77
import android.view.View;
88
import android.view.ViewGroup;
9-
import android.widget.ImageView;
9+
import android.widget.Button;
1010
import android.widget.LinearLayout;
11-
import android.widget.TextView;
1211

1312
import androidx.annotation.Nullable;
1413

@@ -17,6 +16,7 @@
1716

1817
public class KeyBoardView extends LinearLayout implements View.OnClickListener {
1918

19+
private static final String TAG = "KeyBoardView";
2020
private KeyboardClickListener listener = null;
2121

2222
public KeyBoardView(Context context, @Nullable AttributeSet attrs) {
@@ -55,19 +55,15 @@ public boolean dispatchKeyEventInFullScreen(KeyEvent event) {
5555

5656
@Override
5757
public void onClick(View v) {
58-
if (v instanceof TextView) {
59-
// 如果点击的是TextView
60-
String value = ((TextView) v).getText().toString();
61-
if (!TextUtils.isEmpty(value)) {
62-
if (listener != null) {
63-
listener.onClick(value);
64-
}
65-
}
66-
} else if (v instanceof ImageView) {
67-
// 如果是图片那肯定点击的是删除
68-
if (listener != null) {
69-
listener.onDelete();
70-
}
58+
if (listener == null) {
59+
Log.e(TAG, "onClick: ", new NullPointerException("listener is null"));
60+
return;
61+
}
62+
String value = ((Button) v).getText().toString();
63+
if (value.equals("DEL")) {
64+
listener.onDelete();
65+
} else {
66+
listener.onClick(value);
7167
}
7268
}
7369

lite/src/main/res/drawable/dialog_btn_gray.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

lite/src/main/res/drawable/dialog_btn_white_smoke.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

lite/src/main/res/drawable/dialog_button_selector.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

lite/src/main/res/drawable/ic_cancel.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:viewportWidth="1024"
55
android:viewportHeight="1024">
66
<path
7-
android:fillColor="@color/lib_text_color"
7+
android:fillColor="@color/black"
88
android:pathData="M572.57,504.91l268.82,-268.76a42.73,42.73 0,1 0,-60.43 -60.43l-268.82,268.83 -268.77,-268.83a42.73,42.73 0,0 0,-60.43 60.43l268.83,268.76 -268.83,268.83a42.73,42.73 0,0 0,60.43 60.43l268.77,-268.82L780.97,834.16a42.73,42.73 0,0 0,60.43 -60.43z" />
99
</vector>

lite/src/main/res/drawable/ic_keyboard_delete.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

lite/src/main/res/layout/dialog_alert.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@
1919
android:fontFamily="sans-serif-medium"
2020
android:gravity="center"
2121
android:text="请设置标题"
22-
android:textColor="@color/lib_text_color"
22+
android:textColor="@color/black"
2323
android:textSize="@dimen/lib_sp_16" />
2424

2525
<TextView
2626
android:id="@+id/dialogMessageView"
2727
android:layout_width="match_parent"
28-
android:layout_height="0dp"
29-
android:layout_weight="1"
28+
android:layout_height="wrap_content"
3029
android:gravity="center"
3130
android:paddingHorizontal="@dimen/lib_dp_20"
32-
android:paddingBottom="@dimen/lib_dp_15"
3331
android:text="请设置弹窗信息"
3432
android:textColor="@color/lib_text_color" />
3533

3634
<View
3735
android:layout_width="match_parent"
3836
android:layout_height="@dimen/lib_px_1"
37+
android:layout_marginTop="@dimen/lib_dp_20"
3938
android:background="@color/lib_line_color" />
4039

4140
<LinearLayout
@@ -45,14 +44,15 @@
4544

4645
<Button
4746
android:id="@+id/dialogCancelButton"
47+
style="@style/Widget.MaterialComponents.Button.TextButton"
4848
android:layout_width="0dp"
4949
android:layout_height="match_parent"
5050
android:layout_weight="1"
51-
android:background="@drawable/dialog_button_selector"
52-
android:gravity="center"
51+
android:insetTop="0dp"
52+
android:insetBottom="0dp"
5353
android:text="取消"
5454
android:textColor="@color/red"
55-
android:textSize="@dimen/lib_sp_16" />
55+
android:textSize="@dimen/lib_sp_14" />
5656

5757
<View
5858
android:layout_width="@dimen/lib_px_1"
@@ -61,14 +61,15 @@
6161

6262
<Button
6363
android:id="@+id/dialogConfirmButton"
64+
style="@style/Widget.MaterialComponents.Button.TextButton"
6465
android:layout_width="0dp"
6566
android:layout_height="match_parent"
6667
android:layout_weight="1"
67-
android:background="@drawable/dialog_button_selector"
68-
android:gravity="center"
68+
android:insetTop="0dp"
69+
android:insetBottom="0dp"
6970
android:text="确定"
7071
android:textColor="@color/blue"
71-
android:textSize="@dimen/lib_sp_16" />
72+
android:textSize="@dimen/lib_sp_14" />
7273
</LinearLayout>
7374
</LinearLayout>
7475
</androidx.cardview.widget.CardView>

0 commit comments

Comments
 (0)