Button with text Android [duplicate]

0

I'm developing a mobile application and wanted to leave my application looking like this

ButI'mnotabletoputthetextunderneaththebuttonandputagraybackgroundcoloronthebuttonbecauseI'malreadysettingthebackground-colorofthebuttonwithanimage.

<?xmlversion="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>
    
asked by anonymous 28.08.2017 / 00:02

1 answer

3

Would not it be possible to work with imageview already with the button images created and apply the click event on those imageviews? In my project I did so (the color combination is still ugly, but then I adjust)

Follow the code below:

In the activity of the screen you are creating, use a code like this (adapting to your imageviews corresponding to each button you need) for each imageview:

Declare the objects in the main class, outside the oncreate:

   private ImageView btnImport;

Then you will make a code for each imageview 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 remember that this piece of code of mine, will load a new screen (intent) to the touch of the user in the imageview in question.

    
28.08.2017 / 00:41