除主要以外的其他活动中没有应用栏和抽屉 [英] no app bar and drawer in other activity except main

查看:136
本文介绍了除主要以外的其他活动中没有应用栏和抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要活动

 公共类MainActivity扩展AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar =(工具栏)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
initNavigationDrawer();

}

public void initNavigationDrawer(){

}

mobile_form活动中没有活动

 公共类mobile_form扩展AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
view = findViewById(android.R.id.content);
setContentView(R.layout.activity_mobile_form);
}

style.xml



< pre class =lang-xml prettyprint-override> < resources>
< style name =AppThemeparent =Theme.AppCompat.Light.NoActionBar>
< item name =windowActionBar> false< / item>
< item name =windowNoTitle> true< / item>
< / style>
< / resources>

在所有活动中使用工具栏(Android)



我试过但我认为导航栏是因为尺寸是将抽屉布局添加到我的第二个活动后更改但在那里显示空白颜色。

解决方案

您没有操作栏另一个活动,因为您没有在另一个活动中设置它。这部分代码应添加到每个onCreate方法中:

  toolbar =(工具栏)findViewById(R.id.toolbar); 
setSupportActionBar(toolbar);
initNavigationDrawer();

因为默认情况下,您使用以下命令从任何活动中删除了ActionBar:

 < item name =windowActionBar> false< / item> 
< item name =windowNoTitle> true< / item>

在您的应用程序代码中。



P.S。顺便说一句,这部分代码:

 < android.support.v7.widget.Toolbar 
android:id = @ + id / toolbar
android:layout_width =match_parent
android:layout_height =?attr / actionBarSize
android:background =?attr / colorPrimary
app:popupTheme =@ style / AppTheme.PopupOverlay/>

如果您希望在该活动中使用工具栏,还应添加到每个活动布局文件中。



PSS您应该阅读添加应用栏创建导航抽屉教程。


main activity

 public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        initNavigationDrawer();

    }

    public void initNavigationDrawer() {

    }

no activity in mobile_form activity

public class mobile_form extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view= findViewById(android.R.id.content);
    setContentView(R.layout.activity_mobile_form);
}

style.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

Use Toolbar across all activities (Android)

I tried it but I think navigtion bar is there because the size is changed after adding drawer layout to my second activity but is shows blank white color there.

解决方案

You don't have action bar in another activity, because you do not set it in another activity. This part of code should be added to each onCreate method:

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    initNavigationDrawer();

Because by default, you removed ActionBar from any activity by using:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

in your application code.

P.S. Btw, this part of code:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

Should be also added to each activity layout file, if you wish to use toolbar at that activities.

P.S.S. You should read Adding the App Bar and Creating a Navigation Drawer tutorials from google.

这篇关于除主要以外的其他活动中没有应用栏和抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆