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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:12:11+00:00 2026-05-27T06:12:11+00:00

I have a fragment embedded in a layout. This fragment has a very simple

  • 0

I have a fragment embedded in a layout. This fragment has a very simple view (basically just a styled button with its pressed state being programmatically set).

When I start a new activity from the activity hosting the fragment, and press BACK to go back to the original activity the button is still disabled, but is now showing its unpressed state.

layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

     <fragment
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        class="com.mypackage.NavigationDrawerFragment"
        android:gravity="bottom"
        android:padding="5dp" />>

</RelativeLayout>

fragment_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingBottom="10dp" >

    <Button
            android:id="@+id/nav_home"
            style="@style/navigation_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableTop="@drawable/button_home"
            android:text="HOME"
            android:textColor="@drawable/button_text" />

</RelativeLayout>

In the fragment class, I simply do the following:

  • Disable the button
  • Set the pressed state of the button to true (so the downstate of the drawable is shown)

My fragment class:

public class NavigationDrawerFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        mDrawer = inflater.inflate(R.layout.fragment_navigation_drawer,
            container, false);
        mButtonHome = (Button) mDrawer.findViewById(R.id.nav_home);
        mButtonHome.setEnabled(false);
        mButtonHome.setPressed(true);
    }
}

Any idea why the enabled state of the button is preserved, but the pressed state is not?

  • 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-27T06:12:12+00:00Added an answer on May 27, 2026 at 6:12 am

    As a work around for this, I am now only disabling the button and have added set_enabled=”false” states to my drawables and colors. This state is identical to the “pressed” state.

    drawable/button_home.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/btn_home_down" android:state_enabled="false"/> <!-- disabled state -->
        <item android:drawable="@drawable/btn_home_down" android:state_pressed="true"/> <!-- pressed -->
        <item android:drawable="@drawable/btn_home" /> <!-- default -->
    </selector>
    

    drawable/button_text.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:color="@color/button_down" android:state_enabled="false"/><!-- disabled state -->
        <item android:color="@color/button_down" android:state_pressed="true"/> <!-- pressed -->
        <item android:color="@color/button_up" /> <!-- default -->
    </selector>
    

    This basically has the same effect as calling setEnabled(false) and setPressed(true) on a button.

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

Sidebar

Related Questions

I have a fragment which has its own state (selected buttons, etc). That state
Say I have this HTML fragment <td width=25% style=text-align:right; > <span style=font-family: Arial; font-size:
I have a fragment view that needs replacement with another fragment. When the ListFragment
I have a simple (but performance critical) algorithm in C (embedded in C++) to
I have a fragment I am trying to add into a view. FragmentManager fragMgr=getSupportFragmentManager();
I have a fragment in this form: my $a = $some_href->{$code}{'A'}; # a number
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
I have a fragment with some buttons in it, when a button is clicked
I have a fragment which pulls down data from a webservice and displays this
I have a fragment (F1) with a public method like this public void asd()

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.