0

I want to remove the background white color from the editText Search bar.I want the search bar seems floating above. Please anyone help... Here is the screenshot of search bar.

search_input_style.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="32dp" />
    <padding android:top="12dp" android:left="12dp"
        android:bottom="12dp" android:right="12dp" />
</shape>

EditText xml code

EDIT(Here is the full xml code)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#d8ebb5"
    tools:context=".MainActivity">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/market_rv"
        android:layout_width="411dp"
        android:layout_height="645dp"
        android:layout_marginEnd="8dp"
        android:background="#d8ebb5"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/search_input"
        tools:listitem="@layout/customlist_item_market" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/ic_add_black_24dp"
        app:backgroundTint="#0979D3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.915"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.845" />

    <EditText
        android:id="@+id/search_input"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:background="@drawable/search_input_style"
        android:backgroundTint="#D8EBB5"
        android:drawableLeft="@drawable/ic_search_gray_24dp"

        android:elevation="10dp"


        android:hint="search"
        android:inputType="textPersonName"
        android:textColor="@color/content_text_color"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

Actually this is working properly on emulator but it is not working on actual phone. There is another problem on emulator that is the search bar and the list is overlapped which doesn't occur on actual phone you can see this above screenshot of phone. emulator screenshot is here.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

3 Answers3

1

To elevate you can use . android:elevation="10dp" And set the background color of EditText parent view as android:background="#D8EBB5" If it doesn't work then provide your full xml code.

Hritik Gupta
  • 611
  • 5
  • 20
0

If I understood correctly, you need to change the background color of the EditText's parent to #D8EBB5.

You didn't provide the entire XML code, but just try setting android:background="#D8EBB5" to the first EditText's parent background.

Sharp
  • 1,335
  • 1
  • 12
  • 27
0

Just apply the background color to your parent view. It is just an example:

<LinearLayout
    android:background="@color/...."
    ...>

    <EditText
        android:id="@+id/edittext"
        android:drawableLeft="@drawable/ic_add_24px"
        android:drawableTint="@color/...."
        android:hint="Search"
        />

</LinearLayout>

Then with the Material Components Library apply a MaterialShapeDrawable:

float radius = getResources().getDimension(R.dimen.default_corner_radius);
EditText editText = findViewById(R.id.edittext);
ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
    .toBuilder()
    .setAllCorners(CornerFamily.ROUNDED,radius)
    .build();

MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
shapeDrawable.setStroke(1.0f, ContextCompat.getColor(this,R.color....));
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,android.R.color.transparent));

ViewCompat.setBackground(editText,shapeDrawable);

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841