我有一个工具栏
,我在其中放置了我的 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/