Last active
December 12, 2023 09:41
-
-
Save LeoAndo/5c911d16744ffa36c331c169e4979064 to your computer and use it in GitHub Desktop.
[Android] Spinnerのテキスト色を変える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout 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:orientation="vertical" | |
android:padding="12dp" | |
tools:context=".MainActivity"> | |
<Spinner | |
android:id="@+id/pokemon_type" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:minHeight="48dp" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xxx; // TODO 自分のパッケージ名に変更する | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.ArrayAdapter; | |
import android.widget.Spinner; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final Spinner spinner = findViewById(R.id.pokemon_type); | |
final String[] entries = {"全て", "ほのお", "みず", "でんき"}; | |
spinner.setAdapter(new ArrayAdapter<>(this, R.layout.simple_list_item_1, entries)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:gravity="center_vertical" | |
android:minHeight="?android:attr/listPreferredItemHeightSmall" | |
android:paddingStart="?android:attr/listPreferredItemPaddingStart" | |
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" | |
android:textAppearance="?android:attr/textAppearanceListItemSmall" | |
android:textColor="#FFBB86FC" | |
tools:text="全て" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple_list_item_1.xml が自作したSpinner用のレイアウトファイルになります
実行結果: Pixel 3a API 29 (OSバージョン: 10)
device-2023-12-12-183556.webm