小编Fri*_*iek的帖子

当android:theme被应用于特定按钮时应用程序崩溃

我正在为Android(我的第一个应用程序)做一个简单的计算器应用程序,当我尝试将特定的android:主题应用于按钮时,我遇到了一些问题.

当具有特定主题的按钮尝试在onclick事件中执行活动方法时,问题就出现了.根据我在StackOverflow中搜索的内容,就像按钮的"上下文"一样,特定主题与活动上下文不同,因此它无法找到我的方法来处理活动中写入的onclick.

有我的style.xml,我定义了我的应用程序主题和我的特定按钮主题:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorButtonNormal">#dc000000</item>
        <item name="android:background">#dc262626</item>
        <!-- Customize your theme here. -->
    </style>

    <style name="contextButtonTheme" parent="AppTheme">
        <item name="colorButtonNormal">@color/contextButtonsColor</item>
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

布局xml中有我的按钮:

<Button
    android:layout_width="0dp"
    android:layout_weight="25"
    android:layout_height="match_parent"
    android:text="X"
    android:id="@+id/multButton"
    android:textSize="11pt"
    android:theme="@style/contextButtonTheme"
    android:onClick="onClickButton"/>
Run Code Online (Sandbox Code Playgroud)

我在这里读到的解决方案是将"android:theme"更改为"style",虽然这解决了崩溃,但colorButtonNormal新颜色并未应用:(.

请帮助我D:

PD:抱歉我的英语不好

android themes

5
推荐指数
1
解决办法
178
查看次数

What is exactly null in kotlin and why i can't cause NPE with it?

Look at the following code running in Kotlin REPL:

>>> null.takeIf({1==2})
res4: kotlin.Nothing? = null
Run Code Online (Sandbox Code Playgroud)

Why this don't cause NullPointerException?

kotlin

0
推荐指数
1
解决办法
82
查看次数

标签 统计

android ×1

kotlin ×1

themes ×1