- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个 android 应用程序并想做一个 SettingsActivity。
我的问题是我的矢量可绘制对象不会使其颜色适应夜间或白天主题。
ic_palette_black_24dp.xml:
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/icon_color_on_surface" android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="icon_color_on_surface">#000000</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="icon_color_on_surface">#FFFFFF</color>
</resources>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root_preferences">
<PreferenceCategory android:title="@string/title_preference_design">
<ListPreference
android:entries="@array/preference_list_theme"
android:entryValues="@array/preference_list_theme_values"
android:icon="@drawable/ic_palette_black_24dp"
android:key="list_preference_theme"
android:tint="@color/icon_color_on_surface"
android:tintMode="src_atop"
android:title="@string/preference_category_theme"
app:icon="@drawable/ic_palette_black_24dp" />
</PreferenceCategory>
</PreferenceScreen>
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import java.util.ArrayList;
public class SettingsActivity extends AppCompatActivity {
private ColorHelper colorHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
// Indicate here the XML resource you created above that holds the preferences
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
}
android:tint=""
设置它和
android:tintMode=""
但无论我做什么,图标颜色都保持白色。
android:tint=""
的解决方法确实有效。
最佳答案
解决这个问题的方法是为 fillColor
定义一个资源属性。 .另外,如果我没记错的话,tint
您在矢量的 XML 中定义的内容要么覆盖,要么对 SVG 可绘制对象没有影响。我的drawables没有tint
颜色集和 fillColor
属性对于所有可绘制对象都是动态的。
下面,android:fillColor="?android:attr/textColorSecondary"
由 Android 系统定义并已由 Theme.MaterialComponents.DayNight
处理.您还可以创建自己的 attr 值。
<vector
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="?android:attr/textColorSecondary"
android:pathData="..."
/>
</vector>
textColorPrimary
,
textColorTertiary
来自
?android:attr
对于不同的色调。
关于android - 偏好 fragment 中的图标不适应夜间模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59218581/
我的应用程序使用 Theme.AppCompat.DayNight.NoActionBar AppTheme ,并有一个抽屉导航。我所有的可绘制对象都是 XML 向量,其中的路径是黑色的。对于在我的
我正在使用 Angularjs 开发一个应用程序。我对动画的一个问题感到震惊。 我想将此处以两种模式(夜间和白天模式)显示的方式添加到我的应用程序中。我看到每次更改模式时都可以使用主题提供程序来更改主
我的客户希望在他的应用程序的“设置” View 中有一个 UISwitch 控件,即:“夜间禁用通知”。如果此选项已打开并且现在是晚上,他希望推送他的 API 将发送到移动设备的消息被忽略。这可能吗?
我是一名优秀的程序员,十分优秀!