简体   繁体   中英

Android app UI isn't displaying properly on physical device, unlike emulator

I'm getting into Android development and making a calculator.

The application works properly on a Pixel 3a emulator, but when I try it on my physical Samsung with Android 8.1 the UI isn't what it's supposed to be. The text on the buttons isn't showing, the buttons do appear as if they are being pressed when I press them, and the TextView is updating.

Layout:

 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" tools:ignore="HardcodedText"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="0dp" android:layout_height="0dp" android:orientation="vertical" app:layout_constraintBottom_toTopOf="@+id/guideline" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <TextView android:id="@+id/formula" style="@style/Formula" android:layout_width="match_parent" android:layout_height="wrap_content" tools:text="1-1" /> <TextView android:id="@+id/result" style="@style/Result" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="0" /> </LinearLayout> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.25"/> <androidx.gridlayout.widget.GridLayout android:id="@+id/buttons_layout" android:layout_width="0dp" android:layout_height="0dp" app:columnCount="4" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline" app:rowCount="5"> <Button android:id="@+id/clear" style="@style/MyButton.Additional" android:text="C" /> <Button android:id="@+id/parenthesis" style="@style/MyButton.Additional" android:text="()" /> <Button android:id="@+id/backspace" style="@style/MyButton.Additional" android:foreground="@drawable/backspace" android:foregroundGravity="center"/> <Button android:id="@+id/division" style="@style/MyButton.Arithmetic" android:text="/" /> <Button android:id="@+id/number_seven" style="@style/MyButton" android:text="7" /> <Button android:id="@+id/number_eight" style="@style/MyButton" android:text="8" /> <Button android:id="@+id/number_nine" style="@style/MyButton" android:text="9" /> <Button android:id="@+id/multiplication" style="@style/MyButton.Arithmetic" android:text="*" /> <Button android:id="@+id/number_four" style="@style/MyButton" android:text="4" /> <Button android:id="@+id/number_five" style="@style/MyButton" android:text="5" /> <Button android:id="@+id/number_six" style="@style/MyButton" android:text="6" /> <Button android:id="@+id/subtraction" style="@style/MyButton.Arithmetic" android:text="-" /> <Button android:id="@+id/number_one" style="@style/MyButton" android:text="1" /> <Button android:id="@+id/number_two" style="@style/MyButton" android:text="2" /> <Button android:id="@+id/number_three" style="@style/MyButton" android:text="3" /> <Button android:id="@+id/addition" style="@style/MyButton.Arithmetic" android:text="+" /> <Button android:id="@+id/positive_negative" style="@style/MyButton" android:text="00" /> <Button android:id="@+id/number_zero" style="@style/MyButton" android:text="0" /> <Button android:id="@+id/decimal" style="@style/MyButton" android:text="." /> <Button android:id="@+id/total" style="@style/MyButton.Result" android:text="=" /> </androidx.gridlayout.widget.GridLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Logcat shows:

2021-01-20 07:23:55.156 16582-16582/? E/libpersona: scanKnoxPersonas
2021-01-20 07:23:55.156 16582-16582/? E/libpersona: Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
2021-01-20 07:23:55.161 16582-16582/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2],  Con:u:r:zygote:s0 RAM:SEPF_SAMSUNG-SM-J727A_8.1.0_0004, [-1 -1 -1 -1 0 1]
2021-01-20 07:23:55.162 16582-16582/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=org.obebeokeke.calculator 
2021-01-20 07:23:55.166 16582-16582/? I/zygote: Late-enabling -Xcheck:jni
2021-01-20 07:23:55.229 16582-16582/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
2021-01-20 07:23:55.229 16582-16582/? D/ActivityThread: Added TimaKeyStore provider
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2678)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:63)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
2021-01-20 07:23:55.492 16582-16582/org.obebeokeke.calculator I/zygote:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)

This is what I'm supposed to see/what I am seeing in the emulator

This is what I see on the physical device

EDIT 1:

I have tried invalidating cache/restarting, I also restarted my PC and phone, no change.

EDIT 2:

My friend tried it in his phone and it worked, so somethings wrong with my phone.

Maybe just invalidate chaches and restart?

I did a factory reset on my phone and it worked, no idea why it wasn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM