- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个简单的 android.support.v7.widget.Toolbar
,我想做的就是通过按左上角的“汉堡包”图标打开 NavigationDrawer。 “汉堡包”按钮是可见的,当我开始从左侧拉动时,我看到了按钮上的动画,但按下按钮并没有像我预期的那样打开/关闭 NavigationDrawer。我已按照 [Google 文档][1] 进行操作,但仍然无法弄清楚这一点。抱歉有任何混淆,以下是我目前尝试使用的简化代码:
public class MainActivity extends AppCompatActivity implements
View.OnClickListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("NICK", "button button button..................");
}
});
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
NavigationView n = (NavigationView) findViewById(R.id.nav);
mDrawerLayout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Log.d("NICK", "button button button..................");
}
});
//mDrawerLayout.setDrawerListener(mDrawerToggle);
n.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
////.......
}
mDrawerLayout.closeDrawers(); // CLOSE DRAWER
return true;
}
});
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d("NICK","CWECNEWKVNERIPNVIEWNFVIPEWNVIPEWNVPIEWNVPIEWNVPIEWNVPIRWNVPRWVPO");
switch (item.getItemId()) {
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START); // OPEN DRAWER
Log.d("NICK","CWECNEWKVNERIPNVIEWNFVIPEWNVIPEWNVPIEWNVPIEWNVPIEWNVPIRWNVPRWVPO");
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.drawer, menu);
return true;
}
}
}
事实上我在运行时没有得到任何日志调试语句。
这基本上是我遇到的问题:https://stackoverflow.com/a/26636045/1489990 .我已经按照这个,它只是不起作用。
据我了解,当按下汉堡包图标时会调用 setNavigationOnClickListener
,而这正是我努力的重点是让事件得到正确处理,因为当我按下按钮时我没有获取我的日志声明。让我知道这个想法是否不正确。 https://developer.android.com/reference/android/widget/Toolbar.html#setNavigationOnClickListener(android.view.View.OnClickListener)
我的布局:
ActivityMain.xml
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/d"
android:background="@drawable/home_wall">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_marginBottom="10dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_marginTop="25dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/drawer"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="@+id/imageView"
android:src="@drawable/trans2"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="300dp" />
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/d8"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView"
android:paddingTop="0dp">
<Button
android:layout_width="75dp"
android:layout_height="50dp"
android:text="Gallery"
android:id="@+id/save_button"
android:background="#dd2c00" android:textColor="#fff"
android:layout_below="@+id/Purchases"
android:layout_toRightOf="@+id/start_button"
android:layout_toEndOf="@+id/start_button" />
<Button
android:layout_width="125dp"
android:layout_height="50dp"
android:text="Store"
android:id="@+id/Purchases"
android:background="#ff6e40" android:textColor="#fff"
android:layout_above="@+id/instructions_button6"
android:layout_toLeftOf="@+id/start_button"
android:layout_toStartOf="@+id/start_button"
android:layout_marginBottom="98dp" />
<Button
android:layout_width="75dp"
android:layout_height="50dp"
android:text="Help"
android:id="@+id/instructions_button6"
android:background="#dd2c00" android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/start_button"
android:layout_toStartOf="@+id/start_button"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp" />
<Button
android:layout_width="75dp"
android:layout_height="300dp"
android:text="Start"
android:id="@+id/start_button"
android:background="#ff3d00"
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" />
<Button
android:layout_width="125dp"
android:layout_height="50dp"
android:text="Achievements"
android:id="@+id/Scores"
android:background="#ff6e40" android:textColor="#fff"
android:layout_alignTop="@+id/Purchases"
android:layout_toRightOf="@+id/start_button"
android:layout_toEndOf="@+id/start_button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to the quiz!"
android:id="@+id/textView"
android:textColor="#fff"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp" />
<!-- sign-in button -->
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_above="@+id/start_button"
android:layout_centerHorizontal="true"
android:visibility="visible" />
<!-- sign-out button -->
<Button
android:id="@+id/sign_out_button"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:text="Sign Out"
android:visibility="invisible"
android:background="#dd4b39"
android:textColor="#fff"
android:layout_alignTop="@+id/sign_in_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:id="@+id/nav"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Drawer.xml
:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_menu"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Google Play Games"
android:icon="@drawable/ic_local_airport_white_48dp">
<menu>
<item
android:id="@+id/Sign_in_drawer"
android:icon="@drawable/games_controller_grey"
android:title="Sign in" />
<item
android:id="@+id/ach"
android:icon="@drawable/games_achievements"
android:title="Achievements" />
</menu>
</item>
<item android:title="Start a Quiz"
android:icon="@drawable/ic_local_airport_white_48dp">
<menu>
<item
android:id="@+id/quizStart25"
android:icon="@drawable/ic_local_airport_white_48dp"
android:title="25 Questions" />
<item
android:id="@+id/quizStart10"
android:icon="@drawable/ic_local_airport_white_48dp"
android:title="10 Questions" />
</menu>
</item>
<group
android:checkableBehavior="single">
<item
android:id="@+id/gallery"
android:icon="@drawable/ic_photo_library_white_48dp"
android:title="Gallery" />
<item
android:id="@+id/stats"
android:icon="@drawable/ic_toc_white_48dp"
android:title="Statistics" />
<item
android:id="@+id/store"
android:icon="@drawable/ic_shop_white_48dp"
android:title="Store" />
<item
android:id="@+id/settings"
android:icon="@drawable/ic_settings_white_48dp"
android:title="Settings" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_info_white_48dp"
android:title="About" />
</group>
<item android:title="Support">
<menu>
<item
android:id="@+id/help_drawer"
android:icon="@drawable/ic_help_white_48dp"
android:title="Help" />
<item
android:id="@+id/report"
android:icon="@drawable/ic_report_problem_white_48dp"
android:title="Contact Developer" />
<item
android:id="@+id/GPlusCommunity"
android:icon="@drawable/btn_g_white_normal"
android:title="Google+ Community" />
</menu>
</item>
最佳答案
在您的 ActivityMain.xml 中,工具栏位于 DrawerLayout 之外。那就是问题所在。如果您希望 Toolbar 与 DrawLayout 交互,Toolbar 需要是 DrawerLayout 的子级。
要解决此问题,请将 DrawerLayout 作为 Activity 的根。这是documentation .相关引用是:
To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.
所以基本上,你的 ActivityMain.xml 应该是这样的:
<android.support.v4.widget.DrawerLayout ...>
<RelativeLayout ...>
<android.support.v7.widget.Toolbar .../>
<!-- Your other content goes here -->
</RelativeLayout>
<android.support.design.widget.NavigationView .../>
</android.support.v4.widget.DrawerLayout>
这应该可以解决问题。
关于android - 单击工具栏上的汉堡包图标不会打开抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30824324/
我有几个系统使用 docker-compose 并且没有问题。 但是,我在这里有一个“向下”根本不做任何事情的地方。 'up'虽然完美。这是在 MacOS 上。 该项目的昵称是“ Storm ”,脚本
解释起来确实很奇怪,所以就这样...... 我正在从 phpmyadmin 获取包含未转义单引号的数据。我正在尝试转换'至'通过使用Content-Type: text/html;在 php
伙计们?在这里需要一些帮助。我使用委托(delegate)协议(protocol)将一些字符串从“第二个 View Controller ”传回给它的前一个。 我的数组附加了我在委托(delegate
我有以下 eval() 东西: c = Customer() eval("c.name = row.value('customer', '{c}')".format(c=column_name), {
我写了这个测试类: @ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" }) public class Candi
我这样写代码: @ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" }) @RunWith(SpringJUnit
假设我更改了文件,然后进行 pull 。 Git 会报错,因为本地仓库还没有保存,将被覆盖。如果我然后删除该添加并使文件与以前相同(与远程 repo 相同),那么会发生 pull 吗? 最佳答案 是的
我正在阅读《Java for Dummies》一书,但遇到了问题。我不明白为什么 @Override 不起作用。我确信这与我的代码有关,因为我之前已经获得了一个多态数组来使用覆盖,但它对我来说太简单了
我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,该错误使我的 BeginStoryboard 无法自行停止。我尽可能地简化了代码,但仍然没有发现问题。你认为它可能是什么?
这个问题在这里已经有了答案: Difference between char[] and char * in C [duplicate] (3 个答案) 关闭 7 年前。 我想我知道自己问题的答案,
我一直在使用 java 的 Scanner 类时遇到问题。我可以让它很好地读取我的输入,但问题是当我想要输出一些东西时。给定多行输入,我想在完全读取所有输入后只打印一行。这是我用来读取输入的代码:
对于这个问题,我已经用最简单的术语表达了这一点。 如果元素被点击,'active'类被添加到元素,'active'类从其他元素中移除。 但是,如果该元素是“事件的”并且它被第二次单击,则“事件”类不应
这会在桌面上创建一个新文件夹,但不会将文件夹 .pfrom 的内容 move 到文件夹 .pTo。 int main() { SHFILEOPSTRUCT sf = {0}; TCHA
我有一个关于多线程调试 DLL (/MDd) 和多线程调试 (/MTd) 设置的问题。它们之间的区别很明显:一个是使用动态库,一个是使用静态库。当我使用/MDd 编译我的程序时,一切都进行得很好。但是
我的问题是,如果我在页面加载时创建一个克隆变量,jQuery 只会 append 它一次。奇怪! Click to copy This is an element! $(document)
所以...我是一个开发 django 应用程序的新手,但是当我尝试通过 virtualbox heroku 运行 heroku run python manage.py syncdb 时,它一直在下面
我在 Spring Boot 初始化时遇到了问题。我在一个简单的 Spring Boot 项目中有这个结构。 com.project.name |----App.java (Annoted with
我在 www.7hermanosmx.com/menu.php 页面上有以下代码 - 一切正常,除了黄色框(类 menuholder)应该每行三个相互 float 。他们坚决拒绝这样做!我知道我做错了
我正在尝试在我正在构建的小型网站上添加一个下拉菜单。出于某种原因,我可以获得我想要向下滑动到 fadeOut() 的 div 并执行其他类似的操作,但我无法将它获取到 slideDown()。我不知道
我有一个不能正确 float 的 div。当您切换可见性时,它会覆盖一些当前文本,但我可以稍后移动它。只是好奇为什么它不能正确 float ! Simple Tabs with CSS &am
我是一名优秀的程序员,十分优秀!