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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:21+00:00 2026-05-22T17:23:21+00:00

I have a weird problem going on with defining two separate custom XML button

  • 0

I have a weird problem going on with defining two separate custom XML button definitions. I created a test project solely to replicate the error, so I’ll be adding the full code and screenshots of the problem. Basically, I’d like to use 9-patch images to define custom XML button configurations that can be reused.

I’ve defined two XML files:

z_btn_xml_glossy_blue_lightblue.xml:

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

    <item
        android:state_focused="true"
        android:drawable="@drawable/z_btn_glossy_lightblue" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </item>

    <item
        android:state_pressed="true"
        android:drawable="@drawable/z_btn_glossy_lightblue" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />        
    </item>

    <item
        android:drawable="@drawable/z_btn_glossy_blue" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />        
    </item>
</selector>

z_btn_xml_glossy_black_white.xml:

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

    <item
        android:state_focused="true"
        android:drawable="@drawable/z_btn_glossy_white" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </item>

    <item
        android:state_pressed="true"
        android:drawable="@drawable/z_btn_glossy_white" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />        
    </item>

    <item
        android:drawable="@drawable/z_btn_glossy_black" >
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />        
    </item>
</selector>

As you can see, both of these files are essentially the exact same, but using different drawables. My main.xml layout file is:

<?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="wrap_content"
    android:paddingLeft="5dip"
    android:paddingRight="5dip"
    android:paddingTop="0dip"
    android:paddingBottom="3dip" >
    <Button
        android:id="@+id/BTNHostWaitingStartGame"
        android:background="@drawable/z_btn_xml_glossy_blue_lightblue"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:layout_marginRight="2dip"
        android:layout_width="wrap_content"
        android:layout_height="45dip"
        android:layout_weight="1.0"
        android:text="Start Game" />
    <Button
        android:id="@+id/BTNHostWaitingCancelGame"
        android:background="@drawable/z_btn_xml_glossy_black_white"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:layout_marginLeft="2dip"
        android:layout_width="wrap_content"
        android:layout_height="45dip"
        android:layout_weight="1.0"
        android:text="Cancel Game" />
</LinearLayout>

Pretty simplistic, it just creates two buttons. I won’t post the test activity file because all it does is set the layout to R.layout.main.

Here is a screenshot of the Graphical Layout within Eclipse, which looks like what I want the buttons to look like:

Graphical Layout, everything looks good

However, on the emulator, it looks like the following:

The second button is not styled

As you can see, the second button is not being styled. Can anyone shed light on why this is? It is the same on devices as well. Is there some limitation here that I’m just not aware of or not seeing?

Thanks for the help!

  • 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-22T17:23:22+00:00Added an answer on May 22, 2026 at 5:23 pm

    It works on my machine.

    I took your code and placed the selector xml’s in res/drawable. Assuming drawable references in items are images (for example that z_btn_glossy_lightblue refers to res/drawable-hdpi/z_btn_glossy_lightblue.png), I exchanged these references to some images of my own. Works like a charm.

    Try:

    • Make sure you have placed your xml’s
      in the right folder, and make sure
      there are no copies of these files
      mistakenly placed in another folder.
    • Make sure your the drawables you
      refer to in the items do not have any
      namesakes, for example res/drawable/z_btn_glossy_lightblue.xml
    • Test referring to other images that you know work in
      other buttons.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck with a weird problem. I have two files a.c and b.c as
i have a weird problem. i would like to delete an assembly(plugin.dll on harddisk)
I have a weird problem with images in visual web developer, I cant change
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
I have a very weird problem: sometimes when I call nHibernate update to an
I have a weird date rounding problem that hopefully someone can solve. My client
This is a weird problem I have started having recently. My team is developing
This is a really weird problem that I have been having. When I download
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
This is kind of a weird problem, but I have to create a search

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.