gpt4 book ai didi

android - 工具栏从顶部切割。如何显示完整的工具栏?

转载 作者:行者123 更新时间:2023-11-30 00:17:06 25 4
gpt4 key购买 nike

Screenshot

我正在添加 Material 抽屉Material Drawer并制作了一个方法 addNavigationDrawer 来添加抽屉导航并在我从 Firebase Firestore 数据库中获取用户详细信息后调用该方法(您可以在 OnCreate 方法下的 Auth Listener 中找到它)但是在第一次打开此 Activity 时,操作栏被切割为你可以在图像中看到但是当我将它最小化并再次打开它时,它工作得非常好。请建议该怎么做?

这里是Activity的完整代码

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);
}
}

最佳答案

step 1 add this style to value/style

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

step 2 add this style to value/style-v21

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

step 3 and change your layout

<?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>

step 4 add theme to manifest.xml

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

关于android - 工具栏从顶部切割。如何显示完整的工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com