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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:33:24+00:00 2026-06-17T17:33:24+00:00

I created my own widget, a LinearLayout with a TextView (label) and a Spinner.

  • 0

I created my own widget, a LinearLayout with a TextView (label) and a Spinner.

It looks like this in XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    style="@style/MySpinner>
    <TextView android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textStyle="bold"
        android:layout_weight="0.4"
        android:textSize="18sp"
        android:padding="8dp"
        android:enabled="false"/>
    <Spinner android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:entries="@array/thats_me_age_values"
        android:layout_weight="0.6"
        android:spinnerMode="dialog"
        android:padding="8dp"/>
</LinearLayout>

The LinearLayout should get all touch events so it can properly use it’s style (background changes on pressed). The style sets the background attribute to this selector:

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- pressed -->
     <item android:state_pressed="true" android:state_focused="false"> 
         <shape android:shape="rectangle" android:visible="true">
             <corners android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
             <solid android:color="@color/dark_yellow"/>
             <stroke android:width="1dp" android:color="@color/grey"/>
         </shape>
     </item> 
     <!-- focused -->
     <item android:state_focused="true"> 
         <shape android:shape="rectangle" android:visible="true">
             <corners android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
             <solid android:color="@color/dark_yellow"/>
             <stroke android:width="1dp" android:color="@color/grey"/>
         </shape>
     </item> 
     <!-- default -->
     <item>
         <shape android:shape="rectangle" android:visible="true">
             <corners android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
             <solid android:color="@color/yellow"/>
             <stroke android:width="1dp" android:color="@color/grey"/>
         </shape>
     </item>
 </selector>

I have tried overriding the onInterceptTouch methode for the LinearLayout. The log messages are shown on pressed but the background does not change.

@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.i("TOUCH", "onTouchEvent");
    return super.onTouchEvent(event);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    onTouchEvent(ev);
    Log.i("TOUCH", "onInterceptTouchEvent");
    return false;
}
  • 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-17T17:33:25+00:00Added an answer on June 17, 2026 at 5:33 pm

    I think adding android:addStatesFromChildren=”true” to LinearLayout will solve your problem… So when you click/focus your spinner linear layout will change it state to clicked/focused.

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

Sidebar

Related Questions

<?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:background=@color/yellow android:orientation=vertical > <LinearLayout android:id=@+id/progresscontent android:layout_width=266dp android:layout_height=52dp
<?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:background=@color/yellow android:orientation=vertical > <LinearLayout android:id=@+id/progresscontent android:layout_width=266dp android:layout_height=52dp
I have created my own Attached Property like this: public static class LabelExtension {
I created a widget that registers its own script like below class MyWidget extends
I would like to create a widget with the following layout: <LinearLayout orientation=horizontal> <CheckBox
Why does my Android time widget doesn't update on its own? I created a
I've created a custom spinner using my own ProjectSpinnerAdapter. I've also got another class
In jQuery UI, widgets are created like this: $(#selector).accordion({ //options }); How would I
Created javascript widget. Testing on my own domain and its working fine. However when
I've created my own great widget for Samsung Smart TV. How i can publish

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.