我在带有导航抽屉的Android应用程序上工作,但是当我将抽屉的代码添加到现有代码(webview和底栏)时,工具栏不会显示。抽屉有效。
这是我的代码:
MainActivity.java
package julians.de.test;
import android.content.res.Configuration;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnMenuTabSelectedListener;
public class MainActivity extends AppCompatActivity {
private CoordinatorLayout coordinatorLayout;
private SwipeRefreshLayout swipeContainer;
Toolbar toolbar;
DrawerLayout drawerLayoutgesamt;
ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.three_buttons_activity);
swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
drawerLayoutgesamt = (DrawerLayout) findViewById(R.id.drawerlayoutgesamt);
drawerToggle = new ActionBarDrawerToggle(MainActivity.this,drawerLayoutgesamt,R.string.auf, R.string.zu);
drawerLayoutgesamt.setDrawerListener(drawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
drawerToggle.syncState();
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
final WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDisplayZoomControls(true);
myWebView.loadUrl("http://www.apple.com");
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
myWebView.reload();
swipeContainer.setRefreshing(false);
}
});
BottomBar bottomBar = BottomBar.attach(this, savedInstanceState);
bottomBar.setItemsFromMenu(R.menu.three_buttons_menu, new OnMenuTabSelectedListener() {
@Override
public void onMenuItemSelected(int itemId) {
switch (itemId) {
case R.id.recent_item:
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDisplayZoomControls(true);
myWebView.loadUrl("http://www.apple.com");
break;
case R.id.favorite_item:
myWebView.getSettings().setLoadWithOverviewMode(false);
myWebView.getSettings().setUseWideViewPort(false);
myWebView.getSettings().setBuiltInZoomControls(false);
myWebView.getSettings().setDisplayZoomControls(false);
myWebView.loadUrl("http://www.apple.com");
break;
case R.id.location_item:
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDisplayZoomControls(true);
myWebView.loadUrl("http://www.apple.com");
break;
}
}
});
bottomBar.setActiveTabColor("#C2185B");
bottomBar.useDarkTheme(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(new Configuration());
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/three_buttons_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context=".MainActivity">
<android.support.v4.widget.DrawerLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/drawerlayoutgesamt"
>
<!-- Activity Layout-->
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/activitylayout"
android:layout_height="match_parent" >
<include
android:id="@+id/toolbar1"
layout="@layout/tool_bar"
/>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
<!-- Drawer Layout -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawerlayoutsingle"
android:layout_gravity="start"
android:background="#fff"
>
<TextView
android:text="Drawer Layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar1"
android:background="#ffd3d3d3"
android:layout_alignParentTop="true"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true">
</android.support.v7.widget.Toolbar>
styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/drawerarrowstyle1</item>
</style>
<style name="drawerarrowstyle1" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
</style>
</resources>
感谢您的帮助!
答案 0 :(得分:0)
您是否尝试过使用android studio提供的导航抽屉模板,如果是这样,请使用片段作为主要活动代替活动
答案 1 :(得分:0)
DrawerLayout充当窗口内容的顶级容器...要使用DrawerLayout,请将主要内容视图定位为具有match_parent的宽度和高度且没有layout_gravity的第一个子视图
你应该试试这个结构
var express = require('express');
var siteRoutes = express.Router();
var path = require('path');
var passport = require(path.resolve(__dirname, '..', '..', './config/passport.js'));
/*==== /AUTH/GOOGLE ====*/
siteRoutes.route('/auth/google')
.get(function(req, res){
console.log('Google Auth triggered');
passport.authorize('google', { scope : ['profile'] })
});
/*==== /AUTH/GOOGLE/CALLBACK ====*/
siteRoutes.route('/auth/google/callback')
.get(function(req, res){
passport.authorize('google', {
successRedirect : '/app',
failureRedirect : '/login',
failureFlash: 'Invalid Google credentials.'
});
});