Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add padding to drop down list that we get by clicking on spinner?

Tags:

android


I have a Spinner and I have added items to it by specifying it in the xml. Now I want to mention the padding for the list view that is obtained when we click on the spinner (Note, I want padding for the entire list of item and not each item). Below is the code I use currently:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/an_id"
    android_layout_width="match_parent"
    android_layout_height="48dp">

    <Spinner
        android:id="@id/my_id"
        android:entries="@array/my_values" />

</FrameLayout>

arrays.xml:
    <string-array name="my_values">
        <item>1</item>
        <item>2</item>
    </string-array>

Also, I don't want to do this in the java code, I want to do it using xml file. Is this possible?

like image 541
Destructor Avatar asked Mar 15 '23 10:03

Destructor


1 Answers

Yes it is possible. define a popUpTheme as below.

 <Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:textSize="?attr/actionBarSize"
            android:dropDownWidth="200dp"
             />

And add this in your styles.xml

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:padding">8dp</item>
</style>

and yes it works. cheers.

like image 61
Midhun Vijayakumar Avatar answered Apr 24 '23 21:04

Midhun Vijayakumar