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 6148459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:17:07+00:00 2026-05-23T19:17:07+00:00

I have a custom component that is a combination of LinearLayout + ImageViewx2 +

  • 0

I have a custom component that is a combination of LinearLayout + ImageViewx2 + TextView. The custom component is clickable, and I’d like to show give the user visual feedback when they click on it by flashing orange background similar to a button. I created the following drawable hoping to use different styles based on the internal state of the component. Here is the drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_pressed="true" android:drawable="@drawable/sunshine_gradient" />
   <item android:state_focused="true" android:drawable="@drawable/winter_background" />
   <item android:drawable="@drawable/component_background" />
</selector>

I also defined a style that references the drawable:

<style name="navigation_item" parent="android:Theme.Dialog">
    <item name="android:background">@drawable/navigation_item</item>
</style>

Then assigned that to the component using:

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent"
   android:padding="5dp"
   android:orientation="horizontal"
   android:clickable="true"
   style="@style/navigation_item">

<ImageView android:id="@+id/navigationIcon"
           android:layout_height="wrap_content"
           android:layout_width="wrap_content"
           android:layout_marginRight="5dp"/>

<TextView android:id="@+id/navigationTitle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="center_vertical"
          android:layout_weight="1.0"
          android:singleLine="true"
          style="@style/favoriteTitle"
          android:layout_marginRight="5dp"/>

<ImageView android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/right_arrow"/>
</merge>

My component code is:

public class NavigationItem extends LinearLayout {

public NavigationItem(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER);
    setWeightSum(1.0f);
    setClickable(true);

    LayoutInflater.from(context).inflate(R.layout.navigation_item, this, true);

    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.NavigationItem, 0, 0 );

    String title = array.getString(R.styleable.NavigationItem_title);
    if( title == null ) title = "";
    ((TextView)findViewById(R.id.navigationTitle)).setText(title);

    Drawable icon = array.getDrawable(R.styleable.NavigationItem_icon);
    if( icon != null ) {
        ((ImageView)findViewById(R.id.navigationIcon)).setImageDrawable(icon);
    }

    array.recycle();
}

}

It appears the component is picking up the drawable since it does have @drawable/component_background by default. It doesn’t work when I click on it. I don’t see the state change to pressed or focus. Can this be done on default LinearLayout?

  • 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-05-23T19:17:09+00:00Added an answer on May 23, 2026 at 7:17 pm

    Looks like I’m going to answer this one myself. Turns out the merge tag can’t specify style attribute on that tag. So by specifying the style on the usage of NavigationItem in XML or in the code makes this all work out.

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

Sidebar

Related Questions

I have a custom built sign up component that I would like to enhance.
I have a custom component, that contains a list of another components. If I
I have a component where i want to display a custom jtooltip. That is
I have a custom component Comp that gets its position changed as a result
I have a custom component which extends LinearLayout, I need to execute certain statements
I have a custom component, ExportCommandButton, that has two attached properties. This component is
I had a custom MXML component, that I have converted to a pure AS3
I have a JTabbedPane with a custom tab component. That component contains a JLabel
I have built a custom view component that displays a timeline of events. The
I have a custom TitleWindow component that is registered to listen for keyboard events

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.