android-如何更改我的编辑文本和微调器的样式

android-如何更改我的编辑文本和微调器的样式,android,android-edittext,android-spinner,android-theme,android-styles,Android,Android Edittext,Android Spinner,Android Theme,Android Styles,以下是我的微调器和编辑文本的外观: 这些是我在其他地方看到的微调器和编辑文本,我喜欢它们: 如何将edittext和微调器更改为第二个图像 我正在使用appcompact 感谢为微调器样式提供的解决方案: 为微调器创建具有自定义布局的自定义适配器 Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFr

以下是我的微调器和编辑文本的外观:

这些是我在其他地方看到的微调器和编辑文本,我喜欢它们:

如何将edittext和微调器更改为第二个图像

我正在使用appcompact


感谢为微调器样式提供的解决方案: 为微调器创建具有自定义布局的自定义适配器

Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.travelreasons, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
R.layout.simple_spinner_item

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="@style/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />
R.layout.simple_spinner_dropdown_item

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="@style/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/dropdownListPreferredItemHeight"
    android:ellipsize="marquee" />
In styles add your custom dimensions and height as per your requirement.

 <style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">

  </style>

  <style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.TextView.SpinnerItem">

  </style>
Spinner-Spinner=(Spinner)findViewById(R.id.pioedittxt5);
ArrayAdapter=ArrayAdapter.createFromResource(此,
R.array.travelreasons、R.layout.simple\u微调器\u项);
adapter.setDropDownViewResource(R.layout.simple\u微调器\u下拉菜单\u项);
旋转器。设置适配器(适配器);
R.layout.simple\u微调器\u项目
R.layout.simple\u微调器\u下拉菜单\u项
在样式中,根据需要添加自定义尺寸和高度。

摘自

这是您可以用于所有视图的最佳工具,其免费功能非常感谢@

Android Holo颜色生成器允许您轻松为Android应用程序创建具有自己颜色的Android组件,如
EdiText
或spinner。它将生成所有必要的九个补丁资产以及相关的XML可绘制和样式,您可以直接将它们复制到项目中

更新1

此域似乎已过期,但该项目是开源的,您可以在此处找到

试试看

此图像置于
EditText

android:background="@drawable/textfield_activated"


更新2

对于API 21或更高版本,您可以使用
android:backgroundTint

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Underline color change"
        android:backgroundTint="@android:color/holo_red_light" />

为微调器和EditText设置背景将帮助您了解它


现在我可以为您介绍编辑文本部分

像这样定义你的风格

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.vivektest.MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <EditText 
       android:background="@drawable/edit_text_style"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_main"
        android:imeOptions="actionSearch"
        android:singleLine="true"
        />

</RelativeLayout>
res/drawable/edit_text_style.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
      <shape >
          <solid android:color="@color/wine_red" />
      </shape>
  </item>

  <!-- main color -->
  <item android:bottom="1.5dp"
      android:left="1.5dp"
      android:right="1.5dp">
      <shape >
          <solid android:color="@color/white" />
      </shape>
  </item>

  <!-- draw another block to cut-off the left and right bars -->
  <item android:bottom="5.0dp">
      <shape >
          <solid android:color="@color/white" />
      </shape>
  </item>
  </layer-list>

现在在编辑文本中定义相同的内容,如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.vivektest.MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <EditText 
       android:background="@drawable/edit_text_style"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_main"
        android:imeOptions="actionSearch"
        android:singleLine="true"
        />

</RelativeLayout>

希望有帮助

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.vivektest.MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <EditText 
       android:background="@drawable/edit_text_style"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_main"
        android:imeOptions="actionSearch"
        android:singleLine="true"
        />

</RelativeLayout>