Articles → ANDROID → Button Control In Android
Button Control In Android
What Is Button Control?
Example
Click to Enlarge
public void ClickEvent(View view) {
Toast.makeText(this, "Button Clicked", Toast.LENGTH_LONG).show();
}
Click Event Using Setonclicklistener
Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(EditTextDemo.this, "Button Clicked", Toast.LENGTH_LONG).show();
}
});
public class EditTextDemo extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_text_demo);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Toast.makeText(this, "Button Clicked", Toast.LENGTH_LONG).show();
}
}
Output
Click to Enlarge
Imagebutton In Android
Click to Enlarge
Click to Enlarge
Click to Enlarge
Setting Both Image And Text On The Button
Attribute | Description |
---|
android:drawableBottom | The image to be drawn below the text. |
android:drawableEnd | The image to be drawn to the end the text. |
android:drawableLeft | The image to be drawn to the left the text. |
android:drawableRight | The image to be drawn to the right the text. |
android:drawableStart | The image to be drawn to the start of the text. |