Tag: 安卓

Kotlin View setEnabled函数缺失?

在Kotlin中 ,当使用kotlinx.android.synthetic来访问View (例如Button )时, setEnabled()函数是否丢失? isEnabled()函数仍然存在。 我怎么能setEnabled() ?

在kotlin android项目中使用intellij-markdown

我想在一个android kotlin项目中使用intellij-markdown,但是它并不能保证java往返。 现在我正在寻找处理这个问题的最痛苦的方法,因此在这里问 – 也许有人面临同样的问题。 目前所有的解决方案都不是很好,因为它们都与上游不同。 Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code. This is caused by library dependencies that have been compiled using Java 8 or above. If you are using the 'java' gradle plugin in a library submodule add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that […]

无法找到填充字段 – 使用Kotlin与房间数据库

我正在与Room持久性库集成。 我在Kotlin有一个数据类: @Entity(tableName = "story") data class Story ( @PrimaryKey val id: Long, val by: String, val descendants: Int, val score: Int, val time: Long, val title: String, val type: String, val url: String ) @Entity和@PrimaryKey注释用于Room库。 当我尝试构建时,错误是失败的: Error:Cannot find setter for field. Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output […]

Android防止查看消耗事件

我正在尝试创建一个将用于记录所有MotionEvent的视图。 这个视图是在一个Service() ,这是从应用程序链接到我需要记录的事件。 我的问题是,当这个视图在应用程序的顶部,根据需要,所有的事件都在这个视图中消耗。 有没有办法阻止这个视图消耗事件,并​​让View在后面消耗它? 这里是Service()的代码 class GestureTrackViewService : Service(), View.OnTouchListener { var mWindowManager: WindowManager? = null var mDummyView: LinearLayout? = null override fun onBind(p0: Intent?): IBinder? { return null } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val params = WindowManager.LayoutParams( 1080, /* width */ 1920, /* height */ WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE […]

是否有必要知道kotlin获得AAD(Associate Android Developer)认证?

由于谷歌推出了作为Android的官方编程语言kotlin。 所以很容易切换到kotlin …特别适合初学者

UNINITIALIZED_VARIABLE变量_longPressed必须被初始化

我有一个处理程序和Runnable,当runnable执行我需要从我的处理程序中删除回调。 如果我这样做,就这样 private val _handler = Handler() private val _longPressed: Runnable = Runnable { _handler.removeCallbacks(_longPressed) } 编译时错误发生错误UNINITIALIZED_VARIABLE 如果我将removeCallBacks方法移动到函数,错误消失了,我很有趣,有什么区别? private val _longPressed: Runnable = Runnable { removeRunnable() } fun removeRunnable(){ _handler.removeCallbacks(_longPressed) }

Kotlin通用参数在函数中使用

我得到了这个问题的解决方案: 通配符在Kotlin通用的参数 ,但现在我有其他问题,仍然有关kotlin通用 我有一个抽象的类使用像下面的听api回调。 ApiRs是每个API响应对象从中继承的父对象 abstract class ApiCallback<in T : ApiRs> { open fun onSucceed(apiRsModel: T) {} open fun onFailed(code: Int, message: String) { } } 这次我写了一个函数来处理api成功与Retrofit2,比检查的东西和回调到UI,这里是我的功能: fun <T : ApiRs> callbackWithSucceed(apiCallback: ApiCallback<T>?, context: Context, response: Response<out ApiRs>?) { // unexpected error if (response == null) { encounterUnexpectedError(apiCallback, context, null) return } // check http […]

构造函数在kotlin派生类中的可分构造器

这是我之前询问的一个问题的后续。 我使用https://github.com/nekocode/android-parcelable-intellij-plugin-kotlin上的Android Parcelable插件按照bennyl的建议,我将构造函数生成的代码更改为 class ChessClock(context:Context) : TextView(context), Parcelable { lateinit var player:String constructor(context:Context, p:String, angle:Float) : this(context) { player = p rotation = angle } } 这就摆脱了我所问过的语法错误。 我现在还有一个问题,一开始我就忽视了。 该插件为writeToParcel生成了这个代码: override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeString(player) parcel.writeFloat(rotation) parcel.writeLong(mTime) parcel.writeInt(mState) } 和这个构造函数: constructor(parcel: Parcel) :this() { player = parcel.readString() rotation = parcel.readFloat() mTime = parcel.readLong() […]

如果在构造函数中定义类属性,如何编写自定义getter?

我一直在写一个应用程序,首先我声明如下的类签名 data class MClass(val id: Int = 0,val descr: String, val timestamp: Long) 现在需要创建的地方,我必须有一个自定义的getter上面的字段。 我怎样才能编写这个自定义的getter? 我知道,否则我可以写一些类似的东西 data class(){ val id=0 val descr = "" get() = descr + "append smth" val timestamp:Long = 0 }

在压缩AsyncTask中的位图时引发的异常不会停止执行

我有一个写在Kotlin的AsyncTask处理一个位图,并将其存储到内部存储的文件。 我的手机没有可用空间来存放新的位图,所以在写入的时候抛出了IOException,这会导致应用程序崩溃。 这是我的doInBackground()函数: override fun doInBackground(vararg params: Int?): Exception? { if(params[0] == null) throw IllegalArgumentException(); Log.d("PhotoEditTask", "start") var bitmap : Bitmap? = null val degrees = if(params.size == 0) 0 else params[0] ?: 0 bitmap = BitmapProcessing.getBitmapFromUri(sourceUri, resolver) if (bitmap != null) { bitmap = BitmapProcessing.rotateBitmap(bitmap, degrees) var destFile = File(destPath) destFile.delete() BitmapFile.saveBitmapToFile(bitmap, destFile, 85) […]