Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:20:24+00:00 2026-06-12T10:20:24+00:00

I have this StateListDrawable: GradientDrawable gd = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { firstColor, secondColor

  • 0

I have this StateListDrawable:

GradientDrawable gd = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] {
            firstColor, secondColor });
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] { android.R.attr.state_pressed },
            new ColorDrawable(onClickColor));
sld.addState(StateSet.WILD_CARD, gd);

This is my Layout:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <RelativeLayout
        android:id="@+id/actionBar"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:baselineAligned="true" 
        android:descendantFocusability="afterDescendants">

        <ImageButton
            android:id="@+id/actionButtonBack"
            android:layout_width="48dip"
            android:layout_height="48dip"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

        <ImageButton
            android:id="@+id/actionButton3"
            android:layout_width="48dip"
            android:layout_height="48dip"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/actionButton2" />

        <ImageButton
            android:id="@+id/actionButton2"
            android:layout_width="48dip"
            android:layout_height="48dip"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_toLeftOf="@+id/actionButton1" />

        <ProgressBar
            android:id="@+id/actionButton1"
            android:layout_width="48dip"
            android:layout_height="48dip"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:padding="4dip" />

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="48dip"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_toLeftOf="@+id/actionButton3"
            android:layout_toRightOf="@+id/actionButtonBack"
            android:gravity="center"
            android:textSize="14dip"
            android:textStyle="bold" />
    </RelativeLayout>

</merge>

And then I set the drawable like this:

tv.setClickable(false);
tv.setTextColor(textViewColor);
actionBack.setBackgroundDrawable(sld);
action2.setBackgroundDrawable(sld);
action3.setBackgroundDrawable(sld);
tv.setBackgroundDrawable(sld);
pb.setBackgroundDrawable(sld);

When I click in the actionBack button, the whole layout becomes the color I have as onClickButton.

I just want it to behave as if I had pressed a regular-xml-defined button drawable.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:20:26+00:00Added an answer on June 12, 2026 at 10:20 am

    It is because the layout_width of the ‘tv’ (TextView with id android:id=”@+id/tvTitle”) is ‘wrap_content’ so when a color is applied to this view it takes the whole boundary you either need to hardcode the layout_width of TextView or apply color as ShapeDrawable with hardcoded width. Hope this will solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have this problem with PCACompute in Android Opencv2.3.1 because when i call PCACompute my
have this layout css: <?xml version=1.0 encoding=utf-8?> <ScrollView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/ScrollView01 android:layout_width=wrap_content android:layout_height=wrap_content android:scrollbars=vertical> <LinearLayout
Have have this line of code in my form when I create a new
I have created a button in my screen's XML like this: <Button android:text=Lets Get
have this code: void set(list<Person*>* listP){ Person timmy = Person(10); listP->push_back(&timmy); } int main()
I have this class package net.omnosis.mazegame.components; import net.omnosis.mazegame.SlicedBitmap; import android.graphics.Bitmap; public class PlayerLayer extends
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
Updated I have a problem with gradient bitmaps on android 2.3. I read this
I have this piece of code: WebClient web = new WebClient(); System.IO.Stream stream =
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.