私はこの左パディング/マージンに対して私の髪を引っ張ってきましたが、大げさにならない程度に問題は解決しません...これに対する解決策は非常に高く評価されます!私はSOからこれらの答えを試しました、それはいくつかのパディングを移動しましたが、それらのすべてではありませんでした。基本的にすべての答えはに設定し、contentInsetStartとcontentInsetLeftを0dpに設定します。これは左のパディングの一部を削除しますが、まだパディングが表示されます。これはcontentInsetStartとcontentInsetLeftを0dpに設定する前よりも小さくなっています。このソリューションは、サムスンの携帯電話上で動作しますが、などネクサス7、ネクサス9、Dellのビーナス8、として私がテストしたすべての錠剤、 AndroidのActionBarで左余白余白を削除するにはどうすればよいですか?
に、私は多くの人がこの問題を持っていたし、これらは信じられません私が試した答えは、上記の左にパディング/マージンを残しています。
Android: remove left margin from actionbar's custom layout
Android Lollipop, AppCompat ActionBar custom view doesn't take up whole screen width
Android API 21 Toolbar Padding
How to remove default layout's padding/margin
How to remove the margin between the app icon and the edge of the screen on the ActionBar?
スタイル
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/AppThemeActionBar</item>
<item name="logo">@android:color/transparent</item>
</style>
<style name="AppThemeActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="displayOptions">showCustom</item>
<item name="background">@color/blue</item>
<item name="actionBarSize">50dp</item>
<item name="height">50dp</item>
<item name="contentInsetLeft">0dp</item>
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
<item name="android:layout_marginLeft">0dp</item>
</style>
</resources>
活動のレイアウト、activity_main.xml、それは、メインアクティビティクラスのためだけのダミーレイアウトほとんど空だ、カスタムアクションバーのビューは、別のレイアウトファイルです。今
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
、ここではレイアウトアクションバーカスタム
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp" >
<Button
android:id="@+id/btn_home"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#ea6464"
android:text="Home"/>
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/btn_home"
android:gravity="center"
android:textColor="#fff"
android:textStyle="bold"
android:text="Hello"/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_menu_edit"
android:background="@null"/>
</RelativeLayout>
カスタムアクションバーのレイアウトを膨張しmActionBar.setCustomView(mCustomView)に設定MainActivity.javaです。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
Button btnHome = (Button) findViewById(R.id.btn_home);
btnHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Home Button Clicked!", Toast.LENGTH_SHORT).show();
}
});
}
}
この問題でのサンプルアプリケーションは、あなたが代わりにActionBar
のToolBar
を使用してsetContentInsetsAbsolute
を呼び出すか、あなたが本当にアクションバーを維持したい場合は、あなたがそのようにそれを行う必要がありますする必要がありhere
私はあなたがアクションバーの代わりにツールバーを使うべきだと思います –
私はツールバーで試してみたところ、同じ問題があります。 –
だからツールバーやアクションバーがあなたの望むものを動かさなかったら、ツールバーのようなレイアウトを作成して(RelativeLayoutを使うことができます)、ツールバーとして使うことができます –