0

Hello guys so I want to add a border around my spinner. just a rectangular box would work. I have already added the border. The problem is that the border keeps the size of the biggest object in the list not the selected object.

Just if it is not clear, My problem is that I have a border(rectangular box) around the spinner which is great, but the size of of the box is the problem. the size of the box is determined by the largest object in the list. Instead, I want the size of the box to be determined by the selected object from the spinner. So if I choose test the box should be small but if I choose "ajidhfkljhfiidsff1233" the box should become bigger.

I already added a border but it is around the spinner

xml of spinner:

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <Spinner
        android:id="@+id/spinner_for_reason"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/color_for_botton_off"
        android:gravity="center_horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/test"
</androidx.constraintlayout.widget.ConstraintLayout>

xml of color_for_botton_off:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/white" />
    <stroke
        android:width="1dp"
        android:color="#607D8B" />
    <corners android:radius="5dp" />
</shape>

xml spinner_xml_to_design:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textColor="@color/fav"
    android:layout_gravity="center_vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"/>

Main.java:

options_list = new ArrayList<String>();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), R.layout.spinner_xml_to_design, options_list);

dataAdapter.setDropDownViewResource(R.layout.spinner_xml_to_design);
spinner_for_reason.setAdapter(dataAdapter);

Thank you in advance guys any help would be appreciated. :) it is my 2 nd post of overflow

0 Answers0