[英]How do I remove the space of the actionbar icon?
I removed the icon using getActionBar().setDisplayShowHomeEnabled(false); 我使用getActionBar()。setDisplayShowHomeEnabled(false);删除了该图标。
I'm using a imageview with should fill the whole actionbar. 我正在使用imageview应该填充整个动作栏。 I want to do it this way because I want the image as titlebar including the logo and a textview.
我想这样做,因为我希望图像作为标题栏包括徽标和textview。 But still want to be able to use actionbar functions.
但是仍然希望能够使用动作栏功能。 So what happened is that it has a start gap where the icon used to be.
因此,发生的事情是它与图标以前的位置存在一个起点差距。 Using match_parent or fill_parent.
使用match_parent或fill_parent。
titlebar.xml titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@android:color/white">
<ImageView
android:id="@+id/header"
android:contentDescription="@string/app_name"
android:background="@drawable/ic_launcher"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart = "20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop = "5dp"
android:text="@string/titlebarText"
android:gravity ="right"
android:textColor="@android:color/black"
android:textStyle="bold"
/>
</LinearLayout>
http://i.imgur.com/3eTldKh.png http://i.imgur.com/3eTldKh.png
That is what I want to make as actionbar 这就是我要作为动作栏
This fixed my problem : 这解决了我的问题:
MainActivity.java MainActivity.java
// Set up the action bar.
final ActionBar actionBar = getActionBar();
//set custom actionbar
actionBar.setCustomView(R.layout.titlebar);
//Displays the custom design in the actionbar
actionBar.setDisplayShowCustomEnabled(true);
//Turns the homeIcon a View
View homeIcon = findViewById(android.R.id.home);
//Hides the View (and so the icon)
((View)homeIcon.getParent()).setVisibility(View.GONE);
titlebar.xml titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@android:color/white">
<ImageView
android:id="@+id/header"
android:contentDescription="@string/app_name"
android:background="@drawable/ic_launcher"
android:layout_width="150dp"
android:layout_height="150dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/titlebarText"
android:gravity ="right"
android:textColor="@android:color/black"
android:textStyle="bold"
/>
</LinearLayout>
在ImageView
删除android:layout_marginStart = "20dp"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.