Tag: android

如何在android中textview的内容添加笔划

我不想使用图像资源。 textview中的文本应该像上面的image.Is有任何方式可能做这种风格无论是在XML或在Java / KOTLIN代码。 另外我不想用帆布画。 请帮忙。

由于NoClassDefFoundError而导致的工具测试失败

我从今天开始在调试模式下对我的kotlin应用程序进行多重分解,因为库迫使我这样做。 我的问题是,我的用户界面测试不工作了。 我也正在缩小我的apk。 我收到以下错误: FATAL EXCEPTION: MockWebServer Process: [package], PID: 19446 java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/collections/CollectionsKt; at [package].activity.MockedServerTestsBase$dispatcher$1.dispatch(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.processOneRequest(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.processConnection(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.execute(Unknown Source) at okhttp3.internal.NamedRunnable.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: java.lang.ClassNotFoundException: Didn’t find class “kotlin.collections.CollectionsKt” on path: DexPathList[[zip file “/system/framework/android.test.runner.jar”, zip file “/data/app/[package].test-2/base.apk”, zip file “/data/app/[package]-1/base.apk”],nativeLibraryDirectories=[/data/app/[package].test-2/lib/x86, […]

Android:自定义按钮上的背景颜色没有正确设置前的棒棒糖

当我使用一个标准的按钮 样式: match_parent @dimen/login_btn_height false @color/white @dimen/login_buttons_bottom_margin 主题: @color/CrGreen @color/CrGreen @color/CrGreen 一切工作正常,背景颜色设置在每个api级别16+ 但是当我使用我的自定义按钮(用kotlin编写,需要自定义字体) open class CheckrobinButton : Button { val fontPath = “fonts/CoreSansG55.otf” constructor(context: Context) : super(context) { init() } constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) { init() } constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr) { init() } constructor(context: Context?, […]

如何在应用程序中打印数组列表?

如何在Android Studio的应用程序屏幕上显示ArrayList? 它显示: 必需:可编辑! 提供:数组列表 fun sort(view: View) { for (a in 0..myList.size) { if(myList[a]==null) myList[a]=0 } for(a in 0..myList.size) { val b=a var temp=0 for (c in b..0) { if(myList[c]< myList[c-1]) { temp=myList[c] myList[c]= myList[c-1] myList[c-1]=temp } } } ans.text= myList } 请帮忙解决问题。 我对Android Studio颇为陌生,刚刚开始学习如何在Kotlin中制作应用程序。 所以请试着用简单的话来回答。

我无法在Android中的类中初始化我的数组(MutableList)

我刚刚开始与Kotlin和Android工作室。 当在MainActivity.kt我做以下… var tafels: MutableList<MutableList> = java.util.ArrayList() tafels.add(mutableListOf(2, 2, 4)) 一切工作正常。 我可以添加元素到这个ArrayList ,如图所示。 当我尝试在一个新文件中做同样的事情时,在我创建的类中,但是,当我输入时,代码帮助无法识别tafels ,因此在键入tafels之后没有任何建议: class TafelsSommen(){ var tafels: MutableList<MutableList> = java.util.ArrayList() tafels.add(mutableListOf(2, 2, 4)) } 为什么我不能将元素添加到tafels类中的TafelsSommen ?

调用Rooms inMemoryBuilder方法时,Room Persistence Library运行时exception

当遵循设置Room持久性库的教程时,我在Android设备上测试时遇到此错误。 java.lang.RuntimeException:找不到PackageName .AppDatabase的实现。 AppDatabase_Impl不存在 我知道有一个类似的问题,但问题是由于kotlin gradle问题。 可能重复 测试课: @RunWith(AndroidJUnit4.class) public class LocalDatabaseTest { private PhotoDao mPhotoDao; private AppDatabase mDb; @Before public void createDb() { Context context = InstrumentationRegistry.getTargetContext(); mDb = Room.inMemoryDatabaseBuilder(context.getApplicationContext(), AppDatabase.class).build(); mPhotoDao = mDb.photoDao(); } @After public void closeDb() throws IOException { //mDb.close(); } @Test public void testPreConditions() { assertNotNull(mDb); } 道: @Dao public […]

Android:Kotlin TypeCastException:null不能转换为非nulltypes的kotlin.String

我是Kotlin的新手,我正在尝试开发一个音乐应用程序。 我得到这个我无法解决的错误。 当我打开我的应用程序时,歌曲列表显示,点击歌曲重定向到现在显示屏幕,但点击下一个或上一个按钮我的应用程序崩溃。 logcat是一个TypeCast错误,我不明白。 代码如下: class SongPlayingFragment : Fragment() { var myActivity: Activity? = null var mediaplayer: MediaPlayer? = null var startTimeText: TextView? = null var endTimeText: TextView? = null var playpauseImageButton: ImageButton? = null var previousImageButton: ImageButton? = null var nextImageButton: ImageButton? = null var loopImageButton: ImageButton? = null var seekbar: SeekBar? = null […]

如何在Android TextView中将字体样式设置为粗体,斜体和下划线?

我想使TextView的内容粗体,斜体和下划线。 我试了下面的代码,它的工作原理,但不强调。 <Textview android:textStyle="bold|italic" .. 我该怎么做? 任何快速的想法?

房间 – 模式导出目录不提供给注释处理器,所以我们不能导出模式

我正在使用Android数据库组件室 我配置了一切,但是当我编译时,Android Studio会给我提示 模式导出目录不提供给注释处理器,所以我们不能导出模式。 您可以提供room.schemaLocation注释处理器参数或将exportSchema设置为false。 据我所知,这是DB文件的位置 它如何影响我的应用程序? 这里最好的做法是什么? 我应该使用默认位置( false值)?

运行Spek测试显示错误“空测试套件”

与Kotlin熟悉了一下,我想介绍一下另一个Android-Java项目,作为测试的第一步。 我决定直接与Spek开始。 我添加了以下依赖关系来构建要测试的模块的渐变: testCompile ‘junit:junit:4.12’ testCompile “org.jetbrains.kotlin:kotlin-stdlib:1.0.2” testCompile “org.jetbrains.kotlin:kotlin-test-junit:1.0.2” testCompile “org.jetbrains.spek:spek:1.0.25” 其中我使用了SimpleTest类的git仓库的spek-samples: import org.jetbrains.spek.api.Spek import kotlin.test.assertEquals class SampleCalculator { fun sum(x: Int, y: Int) = x + y fun subtract(x: Int, y: Int) = x – y } class SimpleTest : Spek({ describe(“a calculator”) { val calculator = SampleCalculator() it(“should return the result of adding […]