I have a question about how to change the color of the tab view.

Asked 2 years ago, Updated 2 years ago, 24 views

Hello, I'm a beginner who is developing an app with Android Studio. Similar to the picture, we implemented a tab bar with letters under the icon &

Like the picture above, I want to change the color that I specified when I selected one tab. Unselected tabs remain in their first color. Currently, only the underlined bar below the icon changes color when selecting a tab. Where and what coding should I do to make it possible?ㅠ<

android java

2022-09-21 19:52

2 Answers

Try the selector. Below is an example of an Android reference document.

button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/button_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@drawable/button_focused" /> <!-- hovered -->
    <item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
<Button
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/button" />


2022-09-21 19:52

Make two images for each. You can change it.


2022-09-21 19:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.