[英]android actionbar delete space
我做了一個自定義的 android 操作欄,但是當我在手機上測試它時有一個空格......我該如何解決它。 有一些代碼和圖像
custom_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:gravity="center_vertical"
android:background="#FFFFFF">
<ImageView
android:id="@+id/iv_logo"
android:layout_width="139dp"
android:layout_height="23dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:contentDescription="@string/actinobar_logo"
app:srcCompat="@drawable/black_logo" />
</LinearLayout>
主頁activity.java
package com.example.speakorean;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_actionbar);
} catch (Exception e){
System.out.println(e.getMessage());
}
setContentView(R.layout.activity_home);
}
}
使用工具欄而不是使用操作欄
使用下面的代碼
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<include layout="@layout/lay_toolbar" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
刪除填充的主要屬性
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.