如何在 android 上着色和对齐微调项? [英] How to color and alignment spinner item on android?

查看:24
本文介绍了如何在 android 上着色和对齐微调项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改文本颜色并将微调器中的项目对齐到它的中心我该怎么做

I'm try to change text color and align item in spinner to center of it how can I do this

这是我的代码

    String[] li={"1","2","3"};
final Spinner combo = (Spinner)findViewById(R.id.widget30);
ArrayAdapter<String> a = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, li);
combo.setAdapter(a);

谢谢

推荐答案

为此使用自定义视图,并通过调用指定:

Use a custom view for that, and specify by calling:

a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

请注意,您必须在此处使用您自己的视图:R.id.my_simple_spinner_dropdown_item

Note that you have to use your own view here: R.id.my_simple_spinner_dropdown_item

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />

这篇关于如何在 android 上着色和对齐微调项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆