gpt4 book ai didi

android - 微调器下拉外边框

转载 作者:行者123 更新时间:2023-11-29 19:57:53 26 4
gpt4 key购买 nike

如何为整个下拉菜单而不是项目本身设置边框?

期望:

也许看不清楚,但我对整个下拉菜单外的白色边框很感兴趣。见红字

enter image description here

现实:

enter image description here

spinner_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_blue_dark">

<TextView
android:id="@+id/tv_spinner_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:gravity="center_vertical|start"
style="@style/sp_squared_style"/>

<ImageView
android:id="@+id/iv_underline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="6dp"
android:background="@drawable/ic_underline"/>
</LinearLayout>

最佳答案

感谢 Ben-J 评论和 http://stackoverflow.com/questions/33222207/how-to-add-padding-to-drop-down-list-that-we-get-by-clicking-on-spinner answer 我使用此代码使用 ThemeOverlay.AppCompat.Light 子样式创建边框。

这将为外部列表覆盖创建填充,这将显示底层覆盖背景。您还需要为列表项设置一个明确的背景,这样它们就不会透明。

layout/main_layout.xml:

<Spinner xmlns:app="http://schemas.android.com/apk/res-auto"
app:popupTheme="@style/LangList_SpinnerPopupOverlay" />

values/styles.xml:

<style name="LangList_SpinnerPopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<!-- border width -->
<item name="android:padding">1dp</item>
<!-- border color -->
<item name="android:background">#f00</item>
</style>

layout/spinner_list_item.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/itemText"
android:background="#fff"/>
</LinearLayout>

layout/spinner_view.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/itemText"/>
</LinearLayout>

CustomListAdapter.java:

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomListAdapter extends ArrayAdapter<CustomListItem> {

private Context context;

public CustomListAdapter(Context context, List<CustomListItem> items) {
super(context, R.layout.spinner_list_item, items);
this.context = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// spinner layout (when closed)
int layoutId = R.layout.spinner_view;
return createView(position, convertView, parent, layoutId);
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// dropdown list layout
int layoutId = R.layout.spinner_list_item;
return createView(position, convertView, parent, layoutId);
}

private View createView(int position, View convertView, ViewGroup parent, int layoutId) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(layoutId, null);
}

TextView itemText = convertView.findViewById(R.id.itemText);

CustomListItem item = getItem(position);
if (item != null) {
itemText.setText(item.getText());
}

return convertView;
}

}

https://i.imgur.com/SKAW0Vw.png

关于android - 微调器下拉外边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36545841/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com