Reputation: 4122
I have a simple selector that has a selected state so I can setSelected(true) on my Button and it shows it to be selected. I'm creating an ActionBar type looking thing. It works well on some android devices (nexus tablet) (v4.1.2) but on Samsung Galaxy S2 (v2.3.6) it hides the text of the button when I invoke setSeletcted(true) state. Anyone know why this could be happening?
My *button_tab_selected* and *button_tab* png image resources are both 47x47 9 patches.
drawable_tabcontrolbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_tab_selected" android:state_selected="true"/>
<item android:drawable="@drawable/button_tab"/>
</selector>
Layout Code
<Button
android:id="@+id/button_draws"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/drawable_tabcontrolbutton"
android:padding="0dp"
android:text="DRAWS"
android:textSize="18sp" />
<Button
android:id="@+id/button_results"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/drawable_tabcontrolbutton"
android:padding="0dp"
android:text="RESULTS"
android:textSize="18sp" />
Java Code
final Button button_draws = (Button) findViewById(com.tattsbet.android.R.id.button_draws);
button_draws.setSelected(true);
final Button button_results = (Button) findViewById(com.tattsbet.android.R.id.button_results);
button_draws.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
button_draws.setSelected(true);
button_results.setSelected(false);
drawsSelected();
}
});
button_results.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
button_results.setSelected(true);
button_draws.setSelected(false);
resultsSelected();
}
});
Upvotes: 0
Views: 805
Reputation: 6582
It might be a Button style problem. You should define an exact color by using the textColor attribute in your xml. White background/white text might be the cause. Styles can be different phone to phone, version to version.
It's good to explicitly define all style properties to avoid these kind of problems.
Upvotes: 1