/ / Android Lollipop, як змінити колір для різних елементів інтерфейсу (ProgressBar, Switch, TextInput) - android, react-native

Android Lollipop, як змінити колір для різних елементів інтерфейсу (ProgressBar, Switch, TextInput) - андроїд, реактивний

У мене є ProgressBar, Switch і TextInput, і мені потрібно мати можливість вказати інший колір для кожного з них.

Коли я це роблю, він змінює колір усіх 3 предметів.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#e8c4c7</item>
</style>

Я шукаю команду, яка лише змінює колір елемента інтерфейсу, який я хочу.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="progressBar">#aaaaaa</item>
<item name="switch">#bbbbbb</item>
<item name="textInput">#cccccc</item>
</style>

На жаль, я не в змозі змінити стиль для кожного елемента безпосередньо (тому що я використовую ReactNative). Мені потрібно рішення, яке використовує ці глобальні налаштування.

Відповіді:

3 для відповіді № 1

style.xml:

<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!--   your app branding color for the app bar, also for button color-->
<item name="android:colorPrimary">@color/primary</item>
<!--   darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!--   theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
<!--progress bar theme-->
<item name="android:progressBarStyle">@style/myprogress</item>
<!--switch button theme-->
<item name="android:switchStyle">@style/myswith</item>
</style>
</resources>

<!--progress bar style,-->
<style name="myprogress" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:background">@color/white_color</item>
</style>

<style name="myswitch" parent="Widget.AppCompat.CompoundButton.Switch"></style>

Manifest.xml:

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Приклад:введіть опис зображення тут


0 для відповіді № 2

Деякі такі коди:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:progressBarStyle">@style/progress</item>
<item name="android:switchStyle">@style/swith</item>
<item name="android:textAppearance">@style/text</item>

</style>

<style name="progress" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:background"></item>
</style>

<style name="swith" parent="Widget.AppCompat.CompoundButton.Switch"></style>
<style name="text" parent="TextAppearance.AppCompat"></style>