大约有 366 项符合查询结果(耗时:0.0370秒) [XML]
Running code in main thread from another thread
...
Kotlin versions
When you are on an activity, then use
runOnUiThread {
//code that runs in main
}
When you have activity context, mContext then use
mContext.runOnUiThread {
//code that runs in main
}
When you are in ...
How to make a copy of a file in android?
...
Kotlin extension for it
fun File.copyTo(file: File) {
inputStream().use { input ->
file.outputStream().use { output ->
input.copyTo(output)
}
}
}
...
Android Bitmap to Base64 String
...hat file to a Base64 string.
Here is how to do that in easy copy-paste (in Kotlin). Note you must close the base64FilterStream to truly flush its internal buffer.
fun convertImageFileToBase64(imageFile: File): String {
return FileInputStream(imageFile).use { inputStream ->
ByteArray...
Computed read-only property vs function in Swift
...
Well, you can apply Kotlin 's advices https://kotlinlang.org/docs/reference/coding-conventions.html#functions-vs-properties.
In some cases functions with no arguments might be interchangeable
with read-only properties. Although the semant...
How do I create ColorStateList programmatically?
...
Here's an example of how to create a ColorList programmatically in Kotlin:
val colorList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_enabled), // Disabled
intArrayOf(android.R.attr.state_enabled) // Enabled
),
intAr...
Is there a method that works like start fragment for result?
...nceState: Bundle?) {
super.onCreate(savedInstanceState)
// Use the Kotlin extension in the fragment-ktx artifact
setResultListener("requestKey") { key, bundle ->
// We use a String here, but any type that can be put in a Bundle is supported
val result = bundle.getStrin...
Remove the error indicator from a previously-validated EditText widget
...
In Kotlin:
editText.error = null
Kotlin Extension Function:
To make it more readable, you could add this extension function
fun EditText.clearError() {
error = null
}
In Java:
editText.setError(null);
...
How do I add a Fragment to an Activity with a programmatically created content view
...onfig.APPLICATION_ID + ".DEBUG_EXAMPLE_TWO_FRAGMENT_TAG";
// ...
}
Kotlin
If you are using Kotlin make sure to take a look at what the Kotlin extensions by Google provide or just write your own.
share
|
...
How can I pass a Bitmap object from one activity to another
...ent.
Implementation
The function is contained in a separate thread using Kotlin Coroutines because the Bitmap compression is chained after the Bitmap is created from an url String. The Bitmap creation requires a separate thread in order to avoid Application Not Responding (ANR) errors.
Concepts U...
How to implement onBackPressed() in Fragments?
...turn true;
} else {
return false;
}
}
}
KOTLIN SOLUTION
1 - Create Interface
interface IOnBackPressed {
fun onBackPressed(): Boolean
}
2 - Prepare your Activity
class MyActivity : AppCompatActivity() {
override fun onBackPressed() {
val fragmen...