自定义 ActionBar 问题
Custom ActionBar Issues
我已经从我的应用程序中删除了默认操作栏,并使用工具栏从头开始添加了一个自定义操作栏。我在操作栏中放置了一个 imageView,但我面临两个问题:
1) imageView 没有响应,因此它不适用于所有设备。我该怎么做才能实现这种响应能力?
2) 我的应用程序中也有一个 OptionsMenu,在 Toggle 旁边是我的应用程序的标题。因为我希望我的图像在 ActionBar 内居中,所以我不希望那里有标题。我怎样才能将它从 ActionBar 中删除?
提前感谢您的帮助和时间!
1) 不要为 ImageView 使用固定值,为工具栏自定义布局中的 imageview 提供权重。
2) layout_gravity="center" 可能对你有帮助
第 1 期:
如果您的图片没有响应。您必须放置不同大小的图像才能支持高端设备。把想要的图片放到文件夹drawable/drawable-hdpi/drawable-mdpi.....
- /drawable-ldpi 对于低密度屏幕。
- /drawable-mdpi 适用于中密度屏幕。
- /drawable-hdpi 对于高分辨率屏幕。
- /drawable-xhdpi 对于超高分辨率屏幕。
问题 2:
删除工具栏标题
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setTitle("");
图像视图居中。将您的自定义视图编辑为居中。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_icon"
android:layout_gravity="center"/>
</LinearLayout>
我已经从我的应用程序中删除了默认操作栏,并使用工具栏从头开始添加了一个自定义操作栏。我在操作栏中放置了一个 imageView,但我面临两个问题:
1) imageView 没有响应,因此它不适用于所有设备。我该怎么做才能实现这种响应能力? 2) 我的应用程序中也有一个 OptionsMenu,在 Toggle 旁边是我的应用程序的标题。因为我希望我的图像在 ActionBar 内居中,所以我不希望那里有标题。我怎样才能将它从 ActionBar 中删除?
提前感谢您的帮助和时间!
1) 不要为 ImageView 使用固定值,为工具栏自定义布局中的 imageview 提供权重。 2) layout_gravity="center" 可能对你有帮助
第 1 期:
如果您的图片没有响应。您必须放置不同大小的图像才能支持高端设备。把想要的图片放到文件夹drawable/drawable-hdpi/drawable-mdpi.....
- /drawable-ldpi 对于低密度屏幕。
- /drawable-mdpi 适用于中密度屏幕。
- /drawable-hdpi 对于高分辨率屏幕。
- /drawable-xhdpi 对于超高分辨率屏幕。
问题 2:
删除工具栏标题
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setTitle("");
图像视图居中。将您的自定义视图编辑为居中。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_icon"
android:layout_gravity="center"/>
</LinearLayout>