PTR 9
PTR 9
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="@+id/simpleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Toggle ON"
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_camera"
android:contentDescription="Camera Button"
android:background="?android:attr/selectableItemBackgroundBorderless"/>
</LinearLayout>
Java file
package com.example.buttondemo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
Button simpleButton;
ToggleButton toggleButton;
ImageButton imageButton;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleButton = findViewById(R.id.simpleButton);
toggleButton = findViewById(R.id.toggleButton);
imageButton = findViewById(R.id.imageButton);
simpleButton.setOnClickListener(new View.OnClickListener() {
@Override
});
toggleButton.setOnClickListener(new View.OnClickListener() {
@Override
if (toggleButton.isChecked()) {
} else {
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
});