我正在使用 androidx 并且我试图在我的 Mainactivity 中设置一个工具栏,以便我可以添加菜单项。
我到处搜索,但似乎无法尝试解决方案 implementation 'com.android.support:appcompat-v7:28.0.0'
主要活动.class
import androidx.appcompat.widget.Toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
Run Code Online (Sandbox Code Playgroud)
活动_main.xml
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/HeaderBar"
app:layout_scrollFlags="scroll|enterAlways" />
Run Code Online (Sandbox Code Playgroud)
样式文件
<style name="HeaderBar">
<item name="android:background">@color/colorPrimaryDark</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中实现 Google 登录,但我不断收到此错误'android.content.Intent com.google.android.gms.auth.api.signin.GoogleSignInClient.getSignInIntent()' on a null object reference。
我在这里遵循了来自 firebase 网站的教程 --> https://firebase.google.com/docs/auth/android/google-signin
这是我的代码
private void googleSignIn() {
Intent intent = googleSignInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(Objects.requireNonNull(account));
} catch (ApiException e) {
Log.w("hhm", "Google signin failed", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)