如何禁用按下按钮的任何视觉证据?

问题描述 投票:0回答:2

即使按下按钮,我也希望按钮看起来相同。例如,如果我按按钮或任何其他视图,则绿色按钮变为灰色,或者如果视图上方有视图,则下部视图变为上部。此外,还会出现阴影。是否可以使工作按钮(或视图)变为视觉上无法点击的状态?布局和样式XML https://drive.google.com/open?id=1lizFYOKbwWdtRQw2Z4SV-tZKjLWwHPWY

android xml android-studio android-layout view
2个回答
0
投票

尝试将样式更改为以下样式(基本上删除父部分)

<style name="KeyboardKeyWhite" >
        <item name="android:background">@android:color/white</item>
        <item name="android:layout_margin">2dp</item>
    </style>

    <style name="KeyboardKeyBlack" >
        <item name="android:background">@android:color/black</item>
        <item name="android:layout_margin">2dp</item>
        <item name="layout_constraintWidth_percent">0.08</item>
    </style>

更多

尽管以上内容回答了您提出的问题,但是您可以在样式上做更多的事情。例如,您可以在样式中添加尺寸信息,从而减少布局文件的长度。此外,您可以重构尺寸样式:

<!-- Parent style for keyboard keys. -->
<style name="keyboardKey">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">0dp</item>
</style>

<!-- KeyWhite inherits from keyboardKey. -->
<style name="keyboardKey.KeyWhite" >
    <item name="android:background">@android:color/white</item>
    <item name="android:layout_margin">2dp</item>
</style>

<!-- KeyBlack inherits from keyboardKey. -->
<style name="keyboardKey.KeyBlack" >
    <item name="android:background">@android:color/black</item>
    <item name="android:layout_margin">2dp</item>
    <item name="layout_constraintWidth_percent">0.08</item>
</style>

然后在您的布局文件中,调用将看起来像,例如:

<TextView
    android:id="@+id/TextView7"
    style="@style/keyboardKey.KeyWhite"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/TextView6"
    app:layout_constraintTop_toTopOf="@id/topGuideline" />

0
投票

它需要看起来像一个按钮吗?您可以使用任何视图(或至少大多数视图)来触发onClick方法,也许只是使用Textview?您需要做的就是编写方法并将其分配给要触发它的视图的onClick。

© www.soinside.com 2019 - 2024. All rights reserved.