android - 禁用 onClick 效果工具栏

标签 android eclipse android-studio

我有一个工具栏,我在其中放置了我的 Logo ,在应用程序中,当我点击 Logo 时,它会显示点击效果,我根本不想要任何效果。

如果我把它放在我的代码中不起作用:

    toolbar.setClickable(false);
    toolbar.setEnabled(false);
    toolbar.setOnClickListener(null);

我的 xml 上都没有

    android:listSelector="@android:color/transparent" 
    android:cacheColorHint="@android:color/transparent"

这是我放置 Logo 的方式:

        getApplicationContext().registerReceiver(deviceStateListener,intentFilter);
    toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
    toolbar.setNavigationIcon(R.drawable.ic_lycos_logo_home);

最佳答案

您可以将 Toolbar XML 定义为具有 ImageView,如下所示:

toolbar.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:minHeight="?attr/actionBarSize"
    android:background="ANY_HEX_COLOR"
    android:elevation="4dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:src="@drawable/ic_lycos_logo_home"
        android:layout_gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"/>

</android.support.v7.widget.Toolbar>

然后,在您的 ActionBarActivity 上,将此 Toolbar 设置为您的 supportActionBar。

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

setSupportActionBar(toolbar);

如果您想删除标题并只留下您的 Logo ,请尝试:

getSupportActionBar().setDisplayShowTitleEnabled(false);

关于android - 禁用 onClick 效果工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31657725/

相关文章:

android - 如何通过点击按钮显示菜单列表?

android - 如何在用户长按列表项时弹出对话框确认删除?

android - 无法拉取“/system/bin/sh : readlink - QtCreator bug workaround?

java - 并行测试方法

android-studio - Android Studio 设备列表卡在正在加载... Mac

android - 调试 Android 小部件

android - 如何将 ImageView 中的图像与 ImageView 的底部对齐?

eclipse - Windows > 首选项中没有服务器

performance - Gradle构建太慢

java - [Eclipse 未启动] :An error has occured. 查看日志文件为空