Mar*_*one 7 android android-appcompat material-design
我正在操作栏中设置自定义视图.使用SDK操作栏时,它会填充操作栏的宽度,但在使用appcompat版本时则不会.使用appcompat和Toolbar时,为什么我的线性布局不会填充宽度?我能做些什么呢?
这是pre-appcompat的样子:

这就是appcompat的样子.(红色显示我的自定义视图的范围.):

编辑:这是使用@Seidan的显式布局参数提示的样子.(显示应该是白色的黑色文字):

这是我的自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#800"
>
<FrameLayout
android:id="@+id/actionbar_discard"
style="?attr/actionButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<TextView
style="?android:actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/ic_close_white_24dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:paddingRight="20dp"
android:text="@string/actionbar_cancel" />
</FrameLayout>
<FrameLayout
android:id="@+id/actionbar_done"
style="?attr/actionButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
style="?android:actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/ic_check_white_24dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:paddingRight="20dp"
android:text="@string/actionbar_done" />
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以下是我设置操作栏的方法:
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
ab.setCustomView(R.layout.actionbar_discard_done);
Run Code Online (Sandbox Code Playgroud)
appcompat-v7:22.0.0和新的appcompat-v7:22.1.0都出现此问题.
Mar*_*one 10
感谢@Seidan的评论.它让我找到了解决方案.造型问题是由于inflater使用错误的主题,当我给它我的Activity 这个.
总结一下,而不是我在问题代码中的这一行......
ab.setCustomView(R.layout.actionbar_discard_done);
Run Code Online (Sandbox Code Playgroud)
...我有...
View v = LayoutInflater
.from(ab.getThemedContext())
.inflate(R.layout.actionbar_discard_done, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT);
ab.setCustomView(v, params);
Run Code Online (Sandbox Code Playgroud)
哪个给了我......

为什么我们必须在布局和代码中指定match_parent,这是一个谜,但我可以忍受它.
| 归档时间: |
|
| 查看次数: |
3658 次 |
| 最近记录: |