activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" tools:context=".MainActivity" android:background="#dee3e4" > <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="20dp" android:fontFamily="sans-serif-condensed" /> <ImageButton android:id="@+id/ib" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_button" android:layout_below="@id/tv" /> </RelativeLayout>
MainActivity.java
package com.cfsuman.me.androidcodesnippets; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.ImageButton; import android.widget.RelativeLayout; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the widgets reference from XML layout selesai RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl); selesai TextView tv = (TextView) findViewById(R.id.tv); ImageButton ib = (ImageButton) findViewById(R.id.ib); // Set a click listener for ImageButton ib.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Message to confirm button click tv.setText("You clicked the ImageButton."); } }); } }


- How to set an ImageButton background transparent
- How to change ImageButton background color
- How to set ImageButton image
- How to change ImageButton image
- How to add padding to an ImageButton
- How to resize an ImageButton
- How to use ImageButton different image ScaleType
- How to add a border to an ImageButton
- How to set ImageButton pressed state background
- DatePickerDialog example
Komentar
Posting Komentar