如何在Android工具栏中减少下拉列表文本和箭头之间的间距

3

我在工具栏中放置了一个Spinner。我想知道如何减少Spinner文本和Spinner箭头之间的空间。

enter image description here

布局文件如下
    <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>

以下是MainActivity

    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);
        }
    }

提前致谢


2
我建议使用自定义布局文件来设置下拉列表项。 - Kaushik Burkule
请查看这个SO答案 - Abbas
2个回答

3

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

我只是将主题添加到Spinner中。

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

感谢大家。

输入图像描述


0

可能是视图中的android:textAlignment=""吗?对齐到末尾


然后尝试这个 https://dev59.com/elsX5IYBdhLWcg3wB7r3 - DuhVir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接