Skip to content

Commit 2915289

Browse files
committed
feat: resizable action bar
1 parent 804eed4 commit 2915289

4 files changed

Lines changed: 31 additions & 32 deletions

File tree

app/src/main/java/com/wtbruh/fakelauncher/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private void initUI() {
203203
R.id.date,
204204
R.id.lunarDate,
205205
R.id.simCard,
206+
R.id.main_ActionBar
206207
};
207208
if (scale > 0 && scale != 1.0) {
208209
for (int resId : simpleResizableView) {

app/src/main/java/com/wtbruh/fakelauncher/SubActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
import androidx.fragment.app.Fragment;
44
import androidx.fragment.app.FragmentManager;
55
import androidx.fragment.app.FragmentTransaction;
6+
import androidx.preference.PreferenceManager;
67

78
import android.content.Intent;
9+
import android.content.SharedPreferences;
810
import android.graphics.Color;
911
import android.os.Bundle;
1012
import android.util.Log;
1113
import android.view.KeyEvent;
1214
import android.view.MotionEvent;
15+
import android.view.View;
1316
import android.widget.TextView;
1417

1518
import com.wtbruh.fakelauncher.ui.fragment.phone.MenuFragment;
1619
import com.wtbruh.fakelauncher.ui.fragment.BaseFragment;
1720
import com.wtbruh.fakelauncher.ui.BaseAppCompatActivity;
1821
import com.wtbruh.fakelauncher.ui.fragment.phone.OptionMenuFragment;
22+
import com.wtbruh.fakelauncher.ui.fragment.settings.SubSettingsFragment;
1923
import com.wtbruh.fakelauncher.utils.UIHelper;
2024

2125
import java.lang.reflect.Method;
@@ -60,6 +64,13 @@ protected void onCreate(Bundle savedInstanceState) {
6064
* SubActivity 初始化
6165
*/
6266
private void init() {
67+
// 自动调整大小
68+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
69+
float scale = (float) sp.getInt(SubSettingsFragment.PREF_MAIN_UI_HEIGHT_SCALE, 10) / 10;
70+
if (scale > 0 && scale != 1.0) {
71+
View view = findViewById(R.id.actionBar);
72+
UIHelper.resizeView(scale, view);
73+
}
6374
// 设置状态栏颜色为黑色
6475
getWindow().setStatusBarColor(Color.BLACK);
6576
// 设置底部状态栏为默认状态

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,43 @@
3838
<LinearLayout
3939
android:id="@+id/actionBar"
4040
android:layout_width="match_parent"
41-
android:layout_height="wrap_content"
41+
android:layout_height="72dp"
4242
android:orientation="horizontal"
4343
app:layout_constraintBottom_toBottomOf="parent"
4444
app:layout_constraintEnd_toEndOf="parent"
4545
app:layout_constraintStart_toStartOf="parent"
46-
app:layout_constraintTop_toBottomOf="@id/container">
46+
app:layout_constraintTop_toBottomOf="@id/container"
47+
android:gravity="center">
4748

4849
<TextView
4950
android:id="@+id/leftButton"
50-
android:layout_width="wrap_content"
51-
android:layout_height="wrap_content"
52-
android:text="@string/common_leftButton"
53-
android:textColor="@color/white"
54-
android:textSize="48sp" />
55-
56-
<Space
5751
android:layout_width="0dp"
52+
android:layout_weight="1"
5853
android:layout_height="match_parent"
59-
android:layout_weight="1" />
54+
android:text="@string/common_leftButton"
55+
android:textColor="@color/white"
56+
app:autoSizeTextType="uniform"/>
6057

6158
<TextView
6259
android:id="@+id/centerButton"
63-
android:layout_width="wrap_content"
64-
android:layout_height="wrap_content"
60+
android:layout_width="0dp"
61+
android:layout_weight="1"
62+
android:layout_height="match_parent"
6563
android:text="@string/common_leftButton"
64+
android:textAlignment="center"
6665
android:textColor="@color/white"
67-
android:textSize="48sp" />
66+
app:autoSizeTextType="uniform" />
6867

69-
<Space
70-
android:layout_width="0dp"
71-
android:layout_height="match_parent"
72-
android:layout_weight="1" />
7368

7469
<TextView
7570
android:id="@+id/rightButton"
76-
android:layout_width="wrap_content"
77-
android:layout_height="wrap_content"
71+
android:layout_width="0dp"
72+
android:layout_weight="1"
73+
android:layout_height="match_parent"
7874
android:text="@string/common_rightButton"
7975
android:textAlignment="textEnd"
8076
android:textColor="@color/white"
81-
android:textSize="48sp" />
77+
app:autoSizeTextType="uniform" />
8278
</LinearLayout>
8379

8480
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,14 @@
193193
app:strokeTextColor="@color/black"
194194
app:strokeTextWidth="3" />
195195
</LinearLayout>
196-
197-
<!-- <ImageView-->
198-
<!-- android:layout_width="wrap_content"-->
199-
<!-- android:layout_height="wrap_content"-->
200-
<!-- app:layout_constraintStart_toEndOf="@id/cardProvider"-->
201-
<!-- app:layout_constraintTop_toTopOf="parent"-->
202-
<!-- app:srcCompat="@drawable/ic_charge" />-->
203-
204-
205196
</androidx.constraintlayout.widget.ConstraintLayout>
206197

207198

208199

209200
<LinearLayout
210201
android:id="@+id/main_ActionBar"
211202
android:layout_width="match_parent"
212-
android:layout_height="wrap_content"
203+
android:layout_height="72dp"
213204
android:orientation="horizontal"
214205
app:layout_constraintBottom_toBottomOf="parent">
215206

@@ -218,10 +209,10 @@
218209
app:strokeTextColor="@color/black"
219210
app:strokeTextWidth="3"
220211
android:layout_width="0dp"
221-
android:layout_height="wrap_content"
212+
android:layout_height="match_parent"
222213
android:layout_weight="1"
223214
android:text="@string/main_leftButton"
224215
android:textColor="@color/white"
225-
android:textSize="48sp" />
216+
app:autoSizeTextType="uniform" />
226217
</LinearLayout>
227218
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)