我在 Google Play 崩溃日志中看到崩溃,这真的让我很难过。
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3086)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3229)
at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1926)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:6981)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445)
Caused by: androidx.fragment.app.Fragment$InstantiationException:
at androidx.fragment.app.Fragment.instantiate (Fragment.java:462)
at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:50)
at androidx.fragment.app.FragmentState.instantiate (FragmentState.java:80)
at androidx.fragment.app.FragmentManagerImpl.restoreAllState (FragmentManager.java:3109)
at androidx.fragment.app.FragmentController.restoreAllState (FragmentController.java:158)
at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:344)
at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:85)
at com.autotask.jbarra.kotlinmvvm.MainActivity.onCreate (MainActivity.kt:102)
at android.app.Activity.performCreate (Activity.java:7326)
at android.app.Activity.performCreate (Activity.java:7317)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity …Run Code Online (Sandbox Code Playgroud) 我有一个editTexts数组,我这样做:
inputs[i] = new EditText(this);
inputs[i].setWidth(376);
inputs[i].setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
tFields.addView(inputs[i]);
Run Code Online (Sandbox Code Playgroud)
我希望每个角色都能被大写.现在,第一个单词的第一个字母是小写,然后所有字符后面都是大写.我可以在完成后将用户输入的内容转换为大写,但这并不是我想要的.有没有办法让这些字段按照我希望的方式运行?
我正在尝试使用 textview 自动调整大小。我的应用需要支持 Android 6.0 向前,所以我需要使用 Support 库,因为直到 8.0 才添加 autosize textview。我需要以编程方式进行。我试着按照这个答案。现在我的代码是这样的:
val label = TextView(context)
label.text = i.label
val value = TextView(context)
value.text = i.valueFormatted
value.textSize = 48f
label.textSize = 36f
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(value, 1, 48, 1, TypedValue.COMPLEX_UNIT_DIP)
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(label, 1, 24, 1, TypedValue.COMPLEX_UNIT_DIP)
Run Code Online (Sandbox Code Playgroud)
在较新的 Android 版本中,它看起来像我想要的:
但在旧版本中,它搞砸了: