我需要在我的 android 应用程序中实现底部导航视图。中间的图标需要是图像,即公司徽标。但是当我运行该应用程序时,它只出现一个灰色填充的圆形图标。上面的图片显示了我想要的和我得到的。
我已经在这个网站上尝试过其他问题,但是每个答案都告诉我们使用可绘制对象更改 XML 中的 iconTintList,但中心图标是一个具有多种颜色的矢量。
当我尝试将 null 设置为 setIconTintList 方法时,适用于中间图标,但其他图标也会更改为原始颜色。
//This doesn't work to other icons, only for the middle one
mBottomNav.setItemIconTintList(null);
Run Code Online (Sandbox Code Playgroud)
我还尝试获取菜单并仅为中间的设置图标色调列表,就像上面的代码一样,但也不起作用。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mBottomNav.getMenu().findItem(R.id.nav_buy).setIconTintList(null);
}
Run Code Online (Sandbox Code Playgroud)
这是 XML 实现:
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/kmv_background"
app:itemIconTint="@drawable/bottom_nav_item_color"
app:itemTextColor="@drawable/bottom_nav_item_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_navigation" />
Run Code Online (Sandbox Code Playgroud)
这是java实现:
mBottomNav = findViewById(R.id.bottomNavigationView);
mBottomNav.setOnNavigationItemSelectedListener(this);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
使用 JWT 的 API 请求在 Flask 和 Vue.js 中实现。JWT 存储在 cookie 中,服务器为每个请求验证 JWT。
如果令牌已过期,将返回 401 错误。如果您收到 401 错误,请按照以下代码刷新令牌,再次发出原始 API 请求。以下代码适用于所有请求。
http.interceptors.response.use((response) => {
return response;
}, error => {
if (error.config && error.response && error.response.status === 401 && !error.config._retry) {
error.config._retry = true;
http
.post(
"/token/refresh",
{},
{
withCredentials: true,
headers: {
"X-CSRF-TOKEN": Vue.$cookies.get("csrf_refresh_token")
}
}
)
.then(res => {
if (res.status == 200) {
const config = error.config;
config.headers["X-CSRF-TOKEN"] = Vue.$cookies.get("csrf_access_token");
return Axios.request(error.config);
}
})
.catch(error => {
}); …
Run Code Online (Sandbox Code Playgroud)