我正在添加一个BottomNavigationView项目,我希望为所选选项卡添加不同的文本(和图标色调)颜色(以实现灰色非选定选项卡效果).android:state_selected="true"在颜色选择器资源文件中使用不同的颜色似乎不起作用.我还尝试使用android:state_focused="true"或使用其他项目条目android:state_enabled="true",但不幸的是没有效果.还尝试将state_selected属性设置为false(显式)为默认(未选中)颜色,没有运气.
以下是我将视图添加到布局的方法:
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/silver"
app:itemIconTint="@color/bnv_tab_item_foreground"
app:itemTextColor="@color/bnv_tab_item_foreground"
app:menu="@menu/bottom_nav_bar_menu" />
Run Code Online (Sandbox Code Playgroud)
这是我的颜色选择器(bnv_tab_item_foreground.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/darker_gray" />
<item android:state_selected="true" android:color="@android:color/holo_blue_dark" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我的菜单资源(bottom_nav_bar_menu.xml):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_home"
android:icon="@drawable/ic_local_taxi_black_24dp"
android:title="@string/home" />
<item
android:id="@+id/action_rides"
android:icon="@drawable/ic_local_airport_black_24dp"
android:title="@string/rides"/>
<item
android:id="@+id/action_cafes"
android:icon="@drawable/ic_local_cafe_black_24dp"
android:title="@string/cafes"/>
<item
android:id="@+id/action_hotels"
android:icon="@drawable/ic_local_hotel_black_24dp"
android:title="@string/hotels"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助.
我一直在寻找这个解决方案一段时间但没有得到任何解决方案.例如一个解决方案是
self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Stop, target: self, action: nil), animated: true)
Run Code Online (Sandbox Code Playgroud)
此代码将添加一个带有"停止"图像的按钮.就像这样,还有其他解决方案"搜索",刷新"等等.但是,如果我想以编程方式添加按钮,我想要的图像呢?
在我的应用程序中,我需要更改底部导航栏颜色.我看了许多帖子,但无法找到解决方案.我正在使用appCompat库.需要帮助.提前致谢.

V21/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/bgpreview</item>
<item name="android:colorPrimary">@color/MyColor</item>
<item name="android:colorPrimaryDark">@color/MyColor</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textColorPrimary">@color/MyColor</item>
<item name="colorAccent">@color/MyColor</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
<item name="windowActionBar">false</item>
<item name="android:textAllCaps">false</item>
</style>
Run Code Online (Sandbox Code Playgroud) 所以我有这个代码应该更改导航栏标题字体,但它是doenst
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:_dataManager.optionsSettings.fontString size:14], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Run Code Online (Sandbox Code Playgroud)
使用此代码更改后退按钮字体可以正常工作.
//set backbutton font
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:_dataManager.optionsSettings.fontString size:15], NSFontAttributeName,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:normalAttributes
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud) 我刚刚使用默认的Master Details模板创建了一个简单的iOS 7应用程序.
在MasterViewController.m,viewDidAppear方法,我登录了
self.navigationController.navigationBar.frame.size.height
self.navigationController.navigationBar.frame.origin.y
Run Code Online (Sandbox Code Playgroud)
并因此收到44和20.这看起来很奇怪,因为根据我的阅读,iOS 7中的导航栏应该是64点高度并从0点开始,因此它位于状态栏下方.我读到的是
因为状态栏是透明的,所以它后面的视图显示出来
如果您的应用使用自定义图像作为条形图的背景,则需要提供"更高"的图像,使其向上延伸到状态栏后面.导航栏的高度从44点(88像素)更改为64点(128像素).
我想在我的活动中永久隐藏导航栏(不是整个系统ui).现在我正在使用这段代码
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Run Code Online (Sandbox Code Playgroud)
它隐藏了栏,但当用户触摸屏幕时,它再次显示.是否有任何方法可以永久隐藏它直到活动onStop();
早些时候,我在我的项目中使用iOS 6.1.最近我已经切换到iOS 7.因为,我知道很多变化,我更新了我的代码..但我发现了一个奇怪的行为.我在每个屏幕上的视图都隐藏在导航栏下方.重新定位视图解决了iOS7的问题,但是为旧的iOS版本带来了问题.
任何人都可以解释我,原因是什么,为什么会发生?在iOS 7中发生了哪些变化导致了这个问题?
任何帮助,将不胜感激..
我最近将我的 Xcode 更新到 11.4。当我在设备上运行该应用程序时,我注意到从故事板设置时,我的所有导航项的标题都变黑了。

您不能从代码中更改两者,以下代码行不再起作用
self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
Run Code Online (Sandbox Code Playgroud)
我只使用一些 iOS 13 的东西 UINavigationBarAppearance 让它工作
@available(iOS 13.0, *)
private func setupNavigationBar() {
let app = UINavigationBarAppearance()
app.titleTextAttributes = [.foregroundColor: UIColor.white]
app.backgroundColor = Constants.Color.barColor
self.navigationController?.navigationBar.compactAppearance = app
self.navigationController?.navigationBar.standardAppearance = app
self.navigationController?.navigationBar.scrollEdgeAppearance = app
self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释我为什么吗???这是一个关键的错误,还是一些新的隐藏功能?
我想自定义我的NavigationBar按钮并使用我自己的图像.问题是尺寸应该是多少?我发现按钮大小应该是40*40,所以视网膜的图像应该是80*80?
我是iphone开发的新手.我想在导航栏中设置一个活动指示器.我在导航栏下面看到我的活动指示器.我的代码在这里
- (IBAction) gomethod : (id) sender {
xxMapSubviewcontroller = [[XxMapSubviewcontroller alloc] init];
[self.navigationController pushViewController:xxMapSubviewcontroller animated:YES];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
[activityIndicator startAnimating];
[xxMapSubviewcontroller.view addSubview:activityIndicator];
}
Run Code Online (Sandbox Code Playgroud)
如何在导航栏中设置我的活动指示器?请帮帮我.谢谢.