在片段中设置工具栏

时间:2017-05-04 06:14:32

标签: android android-activity android-actionbar fragment toolbar

我的片段中有一个工具栏,我需要设置活动的操作栏,但是,每当我调用getSupportActionBar()方法时,我都会为null,任何人都可以提供帮助吗?

我的活动:

class FinalViewController:UIViewController, UITabBarControllerDelegate {
   override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBarController?.delegate = self
   }

   func tabBarController(_ tabBarController: UITabBarController,didSelect viewController: UIViewController) {
        let tabBarIndex = tabBarController.selectedIndex
        if tabBarIndex == 0 {
            _ =   self.navigationController?.popViewController(animated: true)
        }else{
    //whatever

}
   }
}

Style.xml 该活动正在使用public class MainActivity1 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity1); Fragment fragment = new HomeFragment(); FragmentManager manager = getSupportFragmentManager(); manager.beginTransaction().replace(R.id.main, fragment).commit(); } } 主题

AppTheme.NoActionBar

片段代码:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

0 个答案:

没有答案