I have created a button in my screen’s XML like this:
<Button android:text="Lets Get Started"
android:background="@drawable/btnbg"
android:id="@+id/btn_nav_let_strtd"android:layout_width="wrap_content"
android:layout_height="35px"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:drawableRight="@drawable/arrow"
android:drawableLeft="@drawable/nav_getstart">
</Button>
</LinearLayout>
set click listenrss
private LinearLayout ll_get_started;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation);
btn_nav_lets_get_strtd = (Button) findViewById(R.id.btn_nav_let_strtd);
btn_nav_lets_get_strtd.setClickable(true);
}
private void setOnclickListeners() {
btn_nav_lets_get_strtd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.out.println("clicked");
Toast.makeText(NavigationScreen.this, "fgd",Toast.LENGTH_SHORT).show();
}
});
But when I try to click this button, it is neither clickable nor focusable. How do I set it as clickable?
I am now using a statelist drawable, but it sets the background when focused or clicked. I want to set a permanent background to this button.
And the drawable is not a bitmap, it is a statlist drawable btnbg. XML is below:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="true"
android:dither="true"
android:variablePadding="true" >
<item
android:drawable="@drawable/nav_blue_bar"
android:state_pressed="true"
/>
you should add a listener to listen the clic event on your button like this :