Button with text Android

Asked

Viewed 431 times

0

I am developing a mobile application and wanted to make my application look like this

inserir a descrição da imagem aqui

But I’m not able to put the text under the button and put a gray background color on the button because I’m already setting the background-color of the button with an image.

inserir a descrição da imagem aqui

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tulio.exercicio3.MainActivity">

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="RGM:XXXXX"
    android:textAlignment="center"
    android:textColor="@android:color/darker_gray"

    android:textSize="24sp"
    android:typeface="normal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Fulann"
    android:textAlignment="center"
    android:textColor="@android:color/darker_gray"
    android:textSize="24sp"
    android:typeface="normal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="116dp"
        android:background="@android:color/holo_blue_bright"
        android:text="Principal" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/auto"
        android:text="Auto" />

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="88dp"
        android:background="@drawable/portateis"
        android:text="Portáteis" />


</LinearLayout>


</LinearLayout>

1 answer

3

Wouldn’t it be possible to work with imageview already with the button images created and apply the click event to those imageviews? In my design I did so(the color combination is ugly yet, but then I adjust)

Print

Follows code:

In the screen Activity you are creating, use a code like this (adapting to your images corresponding to each button you need) for each image view:

Declares objects in the main class, outside the oncreate:

   private ImageView btnImport;

Then make a code of these for each image view that needs to be clicked:

btnImport = (ImageView) findViewById(R.id.btnImportID);
btnImport.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent (MainActivity.this, LeitorActivity.class);
        startActivity(intent);
        finish();
    }
});

Just remembering that this excerpt of my code, will load a new screen (Input) at the touch of the user in the imageview in question.

  • how would I do that ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.