Android 工具栏正在从顶部剪切。如何显示完整的工具栏?

Android 工具栏正在从顶部剪切。如何显示完整的工具栏?,android,navigation-drawer,materialdrawer,Android,Navigation Drawer,Materialdrawer,我正在添加material drawer,并创建了一个方法addNavigationDrawer来添加导航drawer,并在我从Firebase Firestore数据库获得用户详细信息后调用该方法(您可以在OnCreate方法下的Auth Listener中找到),但在第一次打开此活动时,正如你在图片中看到的那样,动作栏正在剪切,但当我将其最小化并再次打开时,它的工作状态绝对良好。请建议怎么做 以下是活动的完整代码 public class Main2Activity extends AppC

我正在添加material drawer,并创建了一个方法addNavigationDrawer来添加导航drawer,并在我从Firebase Firestore数据库获得用户详细信息后调用该方法(您可以在OnCreate方法下的Auth Listener中找到),但在第一次打开此活动时,正如你在图片中看到的那样,动作栏正在剪切,但当我将其最小化并再次打开时,它的工作状态绝对良好。请建议怎么做

以下是活动的完整代码

public class Main2Activity extends AppCompatActivity {

ProfileInformationDialog profileInformationDialog;

FirebaseAuth firebaseAuth;
FirebaseAuth.AuthStateListener authStateListener;
FirebaseFirestore db;
DocumentReference documentReference;

Button button;
GoogleApiClient googleApiClient;

/*@BindView(R.id.toolbar)
Toolbar toolbar;*/

ProgressDialog progressDialog;

String user_name,shop_name;
Toolbar toolbar;

Drawer result;

AccountHeader headerResult;


@Override
public void onStart()
{
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    googleApiClient.connect();
    super.onStart();
    firebaseAuth.addAuthStateListener(authStateListener);
}



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

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

    toolbar.setTitle("Hello");

    setSupportActionBar(toolbar);

    //DrawerUtil.getDrawer(Main2Activity.this,toolbar);

    //addNavigationDrawer();
    progressDialog = new ProgressDialog(this);
    db = FirebaseFirestore.getInstance();
    profileInformationDialog = new ProfileInformationDialog(this);

    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    ButterKnife.bind(this);

    button = (Button) findViewById(R.id.log_out);
    firebaseAuth = FirebaseAuth.getInstance();

    authStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

            final FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
            if (firebaseUser != null) {
                progressDialog.setMessage("Loading...");
                progressDialog.show();
                progressDialog.setCancelable(false);

                //User is signed in
                documentReference = db.collection("Users").document(firebaseUser.getUid());

                documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
                    @Override
                    public void onSuccess(DocumentSnapshot documentSnapshot)
                    {
                        if (documentSnapshot != null && documentSnapshot.exists()) {
                            progressDialog.hide();
                            User user1 = documentSnapshot.toObject(User.class);
                            user_name = user1.getName();
                            shop_name = user1.getShop_name();
                            addNavigationDrawer();
                            //DrawerUtil.getDrawer(Main2Activity.this,toolbar);
                            headerResult.updateProfile(new ProfileDrawerItem().withIcon(R.drawable.logout_icon256).withName(user_name));
                            Toast.makeText(Main2Activity.this, "Document Exists", Toast.LENGTH_SHORT).show();
                        }
                        else
                        {
                            progressDialog.hide();
                            Toast.makeText(Main2Activity.this, "No Such Document", Toast.LENGTH_SHORT).show();
                            profileInformationDialog.show();
                            profileInformationDialog.setCancelable(false);
                        }
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e)
                    {
                        progressDialog.hide();
                        Toast.makeText(Main2Activity.this, "Exception " + e, Toast.LENGTH_SHORT).show();
                    }
                });

                Log.d("TAG", "onAuthStateChanged:signed_in:" + firebaseUser.getUid());
            } else {
                // User is signed out
                Log.d("TAG", "onAuthStateChanged:signed_out");
            }
        }
    };


    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
                    new ResultCallback<Status>() {
                        @Override
                        public void onResult(@NonNull Status status)
                        {
                            //Toast.makeText(getApplicationContext(),"Google Logged Out",Toast.LENGTH_SHORT).show();
                        }
                    });

            firebaseAuth.signOut();
            LoginManager.getInstance().logOut();

            startActivity(new Intent(Main2Activity.this,SignInActivity.class));
            finish();
        }
    });


}

private void addNavigationDrawer()
{
    headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(R.drawable.curve_shape)
            .withSelectionListEnabledForSingleProfile(true)
            .addProfiles(
                    new ProfileDrawerItem().withName(user_name).withIcon(R.drawable.logout_icon256)
            )
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile)
                {
                    Toast.makeText(Main2Activity.this, profile.getName() + "", Toast.LENGTH_SHORT).show();
                    return false;
                }
            })
            .build();


    PrimaryDrawerItem makeBillItem = new PrimaryDrawerItem().withIdentifier(1)
            .withName("Make new Bill");

    SecondaryDrawerItem logoutItem = new SecondaryDrawerItem().withIdentifier(2)
            .withName("Log Out").withIcon(R.drawable.logout_icon256);

    result = new DrawerBuilder()
            .withAccountHeader(headerResult)
            .withActivity(this)
            .withToolbar(toolbar)
            .withTranslucentStatusBar(false)
            .withDisplayBelowStatusBar(false)
            .withActionBarDrawerToggle(true)
            .withActionBarDrawerToggleAnimated(true)
            .withCloseOnClick(true)
            .withSelectedItem(-1)
            .addDrawerItems(
                    makeBillItem,
                    new DividerDrawerItem(),
                    logoutItem
            )
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    Toast.makeText(Main2Activity.this, position + " = position", Toast.LENGTH_SHORT).show();
                    return true;
                }
            })
            .build();

}


@Override
public void onStop() {
    super.onStop();
    if (firebaseAuth != null) {
        firebaseAuth.removeAuthStateListener(authStateListener);
    }
}
公共类Main2活动扩展了AppCompative活动{
ProfileInformationDialog ProfileInformationDialog;
FirebaseAuth FirebaseAuth;
FirebaseAuth.AuthStateListener AuthStateListener;
FirebaseFirestore数据库;
文件参考文件参考;
按钮;
GoogleapClient GoogleapClient;
/*@BindView(R.id.toolbar)
工具栏*/
进行对话进行对话;
字符串用户名、店铺名称;
工具栏;
抽屉结果;
AccountHeader headerResult;
@凌驾
public void onStart()
{
GoogleSignenOptions gso=新建GoogleSignenOptions.Builder(GoogleSignenOptions.DEFAULT\u登录)
.requestEmail()
.build();
GoogleapClient=新的GoogleapClient.Builder(此)
.addApi(Auth.GOOGLE\u SIGN\u IN\u API,gso)
.build();
googleApiClient.connect();
super.onStart();
firebaseAuth.addAuthStateListener(authStateListener);
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
toolbar=(toolbar)findviewbyd(R.id.toolbar);
toolbar.setTitle(“Hello”);
设置支持操作栏(工具栏);
//getDrawer(Main2Activity.this,工具栏);
//addNavigationDrawer();
progressDialog=新建progressDialog(此);
db=FirebaseFirestore.getInstance();
profileInformationDialog=新建profileInformationDialog(此);
sdkinInitialize(getApplicationContext());
AppEventsLogger.activateApp(此);
把(这个)绑起来;
按钮=(按钮)findViewById(R.id.log_out);
firebaseAuth=firebaseAuth.getInstance();
authStateListener=新的FirebaseAuth.authStateListener(){
@凌驾
AuthStateChanged上的公共void(@NonNull FirebaseAuth FirebaseAuth){
final FirebaseUser FirebaseUser=firebaseAuth.getCurrentUser();
if(firebaseUser!=null){
progressDialog.setMessage(“加载…”);
progressDialog.show();
progressDialog.setCancelable(假);
//用户已登录
documentReference=db.collection(“用户”).document(firebaseUser.getUid());
documentReference.get().addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公共无效(文档快照文档快照)
{
如果(documentSnapshot!=null&&documentSnapshot.exists()){
progressDialog.hide();
User user1=documentSnapshot.toObject(User.class);
user_name=user1.getName();
shop_name=user1.getShop_name();
addNavigationDrawer();
//getDrawer(Main2Activity.this,工具栏);
headerResult.updateProfile(新ProfileDrawerItem().withIcon(R.drawable.logout_icon256).withName(user_name));
Toast.makeText(Main2Activity.this,“文档存在”,Toast.LENGTH_SHORT.show();
}
其他的
{
progressDialog.hide();
Toast.makeText(Main2Activity.this,“没有这样的文档”,Toast.LENGTH_SHORT.show();
profileInformationDialog.show();
profileInformationDialog.setCancelable(假);
}
}
}).addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e)
{
progressDialog.hide();
Toast.makeText(Main2Activity.this,“Exception”+e,Toast.LENGTH_SHORT.show();
}
});
Log.d(“TAG”、“onAuthStateChanged:signed_in:”+firebaseUser.getUid());
}否则{
//用户已注销
Log.d(“标记”、“onAuthStateChanged:signed_out”);
}
}
};
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Auth.GoogleSignInApi.signOut(googlepiclient.setResultCallback)(
新的ResultCallback(){
@凌驾
public void onResult(@NonNull状态)
{
//Toast.makeText(getApplicationContext(),“Google注销”,Toast.LENGTH\u SHORT.show();
}
});
firebaseAuth.signOut();
LoginManager.getInstance().logOut();
startActivity(新意图(Main2Activity.this,signianctivity.class));
完成();
}
});
}
私有void addNavigationDrawer()
{
headerResult=新帐户HeaderBuilder()
.withActivity(本)
.带车头背景(R.可拉深曲线\ U形)
.使用SelectionListenableForSingleProfile(真)
.addProfiles(
新建ProfileDrawerItem().withName(用户名)。withIcon(R.drawable.logout_icon256)
)
.withOnAccountHeaderListener(新的AccountHeader.OnAccountHeaderListener(){
@凌驾
公共布尔onProfileChanged(视图、IProfile配置文件、布尔currentPro
 <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
 </style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start"> 

       <android.support.design.widget.CoordinatorLayout 
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
             tools:context="com.visky.railway.sec.ui.activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <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" />

    </android.support.design.widget.AppBarLayout>

    <RelativeLayout
         android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior">

       -----------here your layout content---------------

    </RelativeLayout>
 </android.support.design.widget.CoordinatorLayout>

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
   <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:theme="@style/AppTheme.NoActionBar"/>