我遇到了requestFocus的问题.
首先,这是我的源代码:
<EditText
android:id="@+id/etGLNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btGLCalculate"
android:ems="10"
android:hint="@string/gl_num2_hint"
android:inputType="number" />
<EditText
android:id="@+id/etGLNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/etGLNum2"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/btGLCalculate"
android:ems="10"
android:hint="@string/gl_num1_hint"
android:inputType="number">
<requestFocus />
</EditText>
<TextView
android:id="@+id/tvGLResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/etGLNum2"
android:gravity="center"
android:text="@string/result"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btGLCalculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tvGLResult"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/etGLNum1"
android:text="@string/calculate" />
Run Code Online (Sandbox Code Playgroud)
如你所见,焦点必须转到etGLNum1,但它总是转到etGLNum2.
我已经尝试etGLNum1.requestFocus();从我的java文件添加但它没有用.
我该怎么办?
谢谢 :)
我现在正在将一些代码转换为带有 async-await 和Task. 我想知道的一件事是可以在 Task 实例中使用 DispatchQueue ,例如
Task {
await someHeavyStuff()
DispatchQueue.main.async {
someUIThreadStuff()
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,Task 和 DispatchQueue 在处理异步事物方面几乎没有什么不同的机制,所以我担心使用两者可能会弄乱线程系统。
(我知道我可以MainActor.run {}在这种情况下使用)
我需要更改SwitchCompat的轨道颜色.我试过这个,但它对我不起作用.这是我的XML文件的代码
<android.support.v7.widget.SwitchCompat
android:id="@+id/sc_push"
style="@style/switchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="@style/switchStyle"
app:theme="@style/switchStyle" />
Run Code Online (Sandbox Code Playgroud)
这是我的style.xml文件
<style name="switchStyle">
<item name="colorControlActivated">@color/red</item>
<item name="android:colorForeground">@color/gray</item>
</style>
Run Code Online (Sandbox Code Playgroud)
看来问题是什么?
另外,我无法更改活动的颜色或基本应用程序的颜色.我必须改变这个单一视图的颜色.
我需要在 Android 应用程序中使用 Apple 功能实现登录,因此我按照文档的说明进行操作。
这是我的参数: response_type=id_token&client_id=[CLIENT_ID]&redirect_uri=[REDIRECT_URI]&scope=email%20name&response_mode=form_post
但是 OAuth 页面显示“invalid_request”并带有描述:“Invalid responseType”。
他们说如果response_type可以id_token,在那种情况下,response_mode应该form_post让我跟着他们。但我不明白为什么我无法访问 OAuth 页面。
这是我用来访问 OAuth 页面的 uri:https : //appleid.apple.com/auth/authorize? response_type = id_token & client_id =[ CLIENT_ID] & redirect_uri =[ REDIRECT_URI] & scope = email%20name & state =[ STATE] & response_mode =form_post
如果response_type是code,我可以成功访问OAuth的页面和登录。