大约有 850 项符合查询结果(耗时:0.0186秒) [XML]
Get Android Phone Model programmatically
...ies for your device in debug mode using "evaluate expression" dialog using kotlin:
android.os.Build::class.java.fields.map { "Build.${it.name} = ${it.get(it.name)}"}.joinToString("\n")
share
|
imp...
read file from assets
...
one line solution for kotlin:
fun readFileText(fileName: String): String {
return assets.open(fileName).bufferedReader().use { it.readText() }
}
share
|
...
How to get the ActionBar height?
...mplexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
Kotlin:
val tv = TypedValue()
if (requireActivity().theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
val actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, resources.displayMetrics)
}
...
SharedPreferences.onSharedPreferenceChangeListener not being called consistently
...
Kotlin Code for register SharedPreferenceChangeListener it detect when change will happening on the saved key :
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener { share...
Send Email Intent
...m"));
startActivity(Intent.createChooser(emailIntent, "Send feedback"));
Kotlin version
val emailIntent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:abc@xyz.com")
}
startActivity(Intent.createChooser(emailIntent, "Send feedback"))
This was my output (only Gmail + Inbox su...
Convert Bitmap to File
...oo short not fulfilling the purpose. For those how are looking for Java or Kotlin code to Convert bitmap to File Object. Here is the detailed article I have written on the topic. Convert Bitmap to File in Android
public static File bitmapToFile(Context context,Bitmap bitmap, String fileNameToSave) {...
How to change the status bar color in Android?
...atusBarColor" tools:targetApi="lollipop">@color/black</item>
For Kotlin Developers:
window.statusBarColor = ContextCompat.getColor(this, R.color.color_name)
share
|
improve this answer
...
How to remove focus without setting focus to another control?
...
@Levit, you've probably found it by now, but Kotlin.
– prodaea
Sep 11 '16 at 19:08
|
show 3 more comments
...
How to display long messages in logcat
...
Here is a Kotlin version for the @spatulamania answer (especially for lazy/smart peooples):
val maxLogSize = 1000
val stringLength = yourString.length
for (i in 0..stringLength / maxLogSize) {
val start = i * maxLogSize
var en...
android.widget.Switch - on/off event listener?
...
For those using Kotlin, you can set a listener for a switch (in this case having the ID mySwitch) as follows:
mySwitch.setOnCheckedChangeListener { _, isChecked ->
// do whatever you need to do when the switch is toggled her...