0% found this document useful (0 votes)
40 views6 pages

Android Button Types XML & Java Code

The document contains XML and Java code for an Android application layout and functionality. It defines a user interface with various buttons including an ImageButton, a regular Button, and a ToggleButton, along with their respective click event handlers that display Toast messages. The layout uses a ConstraintLayout and sets up window insets for proper display on different devices.

Uploaded by

pagareankita29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

Android Button Types XML & Java Code

The document contains XML and Java code for an Android application layout and functionality. It defines a user interface with various buttons including an ImageButton, a regular Button, and a ToggleButton, along with their respective click event handlers that display Toast messages. The layout uses a ConstraintLayout and sets up window insets for proper display on different devices.

Uploaded by

pagareankita29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical No:-9

XML CODE:-
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image1"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="51dp"
android:background="@drawable/image1"
android:backgroundTint="@color/design_default_color_secondary_variant"
android:text="ImageButton"
android:textSize="20sp"
android:gravity="center"
android:textColor="#39ff14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.316" />

<ImageButton
android:id="@+id/ib"
android:layout_width="124dp"
android:layout_height="61dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.458"
app:srcCompat="@drawable/arrow1" />

<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="68dp"
android:background="@color/design_default_color_secondary_variant"
android:text="Button"
android:gravity="center"
android:textColor="#39ff14"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.521"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.594" />

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="play"
android:drawableLeft="@drawable/button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.737" />

<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_secondary_variant"
android:text="ToggleButton"
android:gravity="center"
android:textColor="#39ff14"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.842" />

<ToggleButton
android:id="@+id/tb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ON"
android:textOn="ON"
android:textOff="OFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.957" />

</[Link]>
JAVA CODE:-

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


ImageButton ib;
Button b1;
ToggleButton tb;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
ib=findViewById([Link]);
b1=findViewById([Link].b1);
tb=findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link]([Link], "Image Button Clicked",
Toast.LENGTH_LONG).show();

}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link]([Link], "Simple Button Clicked",
Toast.LENGTH_LONG).show();

}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
if([Link]())
{
[Link]([Link], "ON",
Toast.LENGTH_LONG).show();

}
else
{
[Link]([Link], "OFF",
Toast.LENGTH_LONG).show();

}
}
});

[Link](findViewById([Link]), (v,
insets) -> {
Insets systemBars =
[Link]([Link]());
[Link]([Link], [Link], [Link],
[Link]);
return insets;
});
}

OUTPUT:-

You might also like