我在网上找到了一些使用Java的指南,它们试图从android获取默认的Drawable listDivider。
在将代码转换为Kotlin后,我得到了以下内容;
val attrs = IntArray(android.R.attr.listDivider)
val ta = context.obtainStyledAttributes(attrs)
mDivider = ta.getDrawable(0)
ta.recycle()但我遇到内存不足异常,应用程序关闭。
我试过检查android.R.attr.listDivider,它只是一个0的列表,R.attr.listDivider不存在(我已经导入了R )。
我真的不确定我还能尝试什么。
编辑:我有种感觉,它可能与主题有关。这是主题的设置,我只在我的应用程序中使用了一个活动,所有的事情都是用片段完成的。
<application
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>然后在styles.xml中
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />EDIT2;我还创建了一个新的应用程序,它只运行代码块,我得到了相同的java.lang.OutOfMemoryError: Failed to allocate a 404238828 byte allocation with 4194304 free bytes and 318MB until OOM错误
发布于 2020-03-07 20:48:48
结果是我错误地初始化了IntArray;
val attrs = intArrayOf(android.R.attr.listDivider)
val a = context.obtainStyledAttributes(attrs)
mDivider = a.getDrawable(0)
a.recycle()https://stackoverflow.com/questions/60564876
复制相似问题