首页 > 解决方案 > 如何减少android工具栏中微调器文本和微调器箭头之间的空间

问题描述

我在工具栏中放置了一个微调器。我想知道如何减少 Spinner Text 和 Spinner Arrow 之间的空间。

在此处输入图像描述

布局文件如下

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:minHeight="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:titleTextColor="@android:color/white"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            >

            <Spinner
                android:id="@+id/spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hi" />

        </androidx.appcompat.widget.Toolbar>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />
    </LinearLayout>

主要活动如下

    public class MainActivity extends AppCompatActivity {
        Spinner spinner;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            // Sets the Toolbar to act as the ActionBar for this Activity window.
            // Make sure the toolbar exists in the activity and is not null
            setSupportActionBar(toolbar);

            spinner = (Spinner)findViewById(R.id.spinner);
            ArrayAdapter mAdapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.spinner, android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(mAdapter);
        }
    }

提前致谢

标签: androidandroid-layoutandroid-toolbar

解决方案


在朋友发布的链接的帮助下,我解决了额外的空间问题

我刚刚将主题添加到 Spinner

<Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
            />

在此处输入图像描述

谢谢大家


推荐阅读