I want to make button to look the same, even it's pressed down. For example, if I press button or any other view, green button becomes grey or if there is view over view, lower view goes upper. Also, shadows appear. Is it possible to make working button (or view) but not visually clickable? Layout and Styles XMLs https://drive.google.com/open?id=1lizFYOKbwWdtRQw2Z4SV-tZKjLWwHPWY
Asked
Active
Viewed 152 times
0
-
Sorry, maybe it answers but I don't understand. I tried some things but nothing changes. I will upload my layout and styles xmls to edited post. – Pranciskus Nov 05 '19 at 21:06
2 Answers
0
Does it need to look like a button? You can use any view (or at least most) to trigger an onClick method, maybe just use a Textview? All you need to do is write the method and assign it to the onClick of the View you want to trigger it.

Stitches S
- 65
- 11
-
Thanks, for answer, but no, it doesn't work in my case. Look at my code I will upload on edited post. They're styles and layout xmls. – Pranciskus Nov 05 '19 at 21:08
-
you can add `android:onClick="METHOD_NAME"` to any of those TextViews in your layout xml – Stitches S Nov 05 '19 at 21:12
-
I mean, white piano keys goes upper than black keys then you press it. Just try my codes and you will understand what I mean. – Pranciskus Nov 05 '19 at 21:16
-
Ok, i see the issue. You can set `android:clickable="false"` to stop that but that is over ridden if you set an onClick method. The problem is in your parent definition, change it from button to Textview ` – Stitches S Nov 05 '19 at 21:46
0
Try changing your styles to the following (essentially remove the parent portion)
<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>
More
While the above answers the question you asked, you can do a lot more with your style. For example you can add the dimension information in the style and so reduce the length of your layout file. Furthermore, you can refactor the dimension 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>
And then in your layout file the calls would look like, for example:
<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" />

Isai Damier
- 976
- 6
- 8
-
Good to hear! I've added a bit more for you in case you want to go deeper with styles. They are very handy for reducing the size of your layout files. – Isai Damier Nov 05 '19 at 21:53
-