Changer微调器样式 - Android Studio

时间:2017-06-06 11:21:15

标签: javascript android xml android-studio spinner

我正在设计"设计"我们为学校项目创建的应用程序。如何在Android Studio上更改微调器的设计(文本大小,文本颜色,微调器颜色等)?

这是我的代码:



public class MainActivity extends AppCompatActivity {

    private String flowerSpinnerValue, modeSpinnerValue;
    private Flower flower;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Spinner flowerSpinner = (Spinner) findViewById(R.id.flowerSpinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.flowers_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        flowerSpinner.setAdapter(adapter);
        flowerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (flowerSpinner.getSelectedItem().equals("Basil")) {
                    flower = new Basil();
                }

                if(flowerSpinner.getSelectedItem().equals("Mint")) {
                    flower = new Mint();
                    System.out.println("jusia");
                }
                if (flowerSpinner.getSelectedItem().equals("Thyme")) {
                    flower = new Thyme();
                }
            }
&#13;
&#13;
&#13;

&#13;
&#13;
<Spinner
        android:id="@+id/flowerSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/ChooseFlower"
        android:layout_toEndOf="@+id/ChooseFlower"
        android:layout_toRightOf="@+id/ChooseFlower"
        android:backgroundTint="?android:attr/actionMenuTextColor"
        android:keepScreenOn="false"
        android:splitMotionEvents="false"
        android:textAlignment="center"
        android:visibility="visible" />
&#13;
&#13;
&#13;

我想我应该在XML代码中改变一些内容,但我不知道是什么。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

  

这对我有用

    String[] columns = new String[] {DatabaseAdapter.ACTIVITYTYPE};
    int[] to = new int[] {R.id.tvSpin};
    final SimpleCursorAdapter mAdapter1 = new SimpleCursorAdapter(this, R.layout.spin_text, location_cursor, columns1, to1);
    mAdapter1.setDropDownViewResource(R.layout.drop_down_view);
    spinner.setAdapter(mAdapter1);

<强> drop_down_view.xml

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

     <TextView
        android:id="@+id/tvSpin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:layout_gravity="center|left"
        android:paddingLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="@color/BGo"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        />


</LinearLayout>

<强> spin_text.xml

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:orientation="horizontal"
     >

        <TextView
            android:id="@+id/tvSpin"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Doctors Name"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product1"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product1"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product2"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product2"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product3"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product3"
            android:textColor="@color/Black"
            android:textSize="12sp" />

         <TextView
            android:id="@+id/tv_Product4"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product4"
            android:textColor="@color/Black"
            android:textSize="12sp" />

          <TextView
            android:id="@+id/tv_Product5"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product5"
            android:textColor="@color/Black"
            android:textSize="12sp" />

    </LinearLayout>
</LinearLayout>