Android 某些设备上被切断的自定义工具栏内容
我的应用程序中的自定义工具栏有问题: 这似乎只发生在某些设备上,例如我的个人电话没有这个问题,但7.1.1上的像素模拟器有这个问题 这里是我正在使用的代码,仅供参考 XML: 最后是布局检查器: 到目前为止,我已经尝试过了,手动设置高度,将高度更改为包裹内容(奇怪的是,两者都产生了正确的比例,但文本消失了),并设置了Android 某些设备上被切断的自定义工具栏内容,android,android-actionbar,android-toolbar,Android,Android Actionbar,Android Toolbar,我的应用程序中的自定义工具栏有问题: 这似乎只发生在某些设备上,例如我的个人电话没有这个问题,但7.1.1上的像素模拟器有这个问题 这里是我正在使用的代码,仅供参考 XML: 最后是布局检查器: 到目前为止,我已经尝试过了,手动设置高度,将高度更改为包裹内容(奇怪的是,两者都产生了正确的比例,但文本消失了),并设置了minHeight(没有效果) 任何帮助都将不胜感激。我设法弄清楚发生了什么事-android:fitsSystemWindows=“true”属性导致了这些问题。我只是简单地添
minHeight
(没有效果)
任何帮助都将不胜感激。我设法弄清楚发生了什么事-android:fitsSystemWindows=“true”属性导致了这些问题。我只是简单地添加了一些手动填充并删除了这个属性,一切都开始正常工作。我在7.1.1的像素模拟器上尝试了你的代码,效果非常好。我可能会在一个新的活动中尝试,以防其他事情影响它。
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:layout_marginLeft="0dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="@drawable/ic_nav"
android:fitsSystemWindows="true"
android:paddingLeft="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/titleContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="50dp">
<ImageView
android:id="@+id/fwLogo"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="left"
android:layout_marginTop="8dp"
android:foregroundGravity="left"
android:gravity="left"
android:padding="7dp"
android:scaleType="fitStart"
app:srcCompat="@drawable/nav_logo" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:foregroundGravity="center"
android:gravity="center"
android:minHeight="50dp"
android:text="Baby And You"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@android:color/white" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</FrameLayout>
Toolbar action = findViewById(R.id.toolbar);
setSupportActionBar(action);
setTitle("");
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
final TypedArray styledAttributes = getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize});
int actionSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
int height = statusBarHeight + actionSize;
action.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));