\n
I'm using the following codes.
\n // java code\npublic class SimpleQns extends AppCompatActivity{\nprotected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.questions);\n\n getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);\n getSupportActionBar().setCustomView(R.layout.actionbar_qns);\n //other codes for app }\n
\nxml layout file with name actionbar_qns.xml
\n<?xml version="1.0" encoding="utf-8"?>\n<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n android:weightSum="5"\n android:background="@drawable/actionbar_qns"\n android:padding="0dp"\n android:layout_margin="0dp">\n\n <Button\n android:id="@+id/play"\n android:layout_width="50dp"\n android:layout_weight="1"\n android:layout_height="50dp"\n android:layout_gravity="center"\n android:text="P"\n />\n <TextView\n android:id="@+id/tv_actionbar_questions"\n android:layout_width="wrap_content"\n android:layout_height="wrap_content"\n android:layout_weight="3"\n android:layout_gravity="center"\n android:gravity="center"\n android:text="Simple Questions"\n android:textColor="@color/white"\n android:textSize="20sp" />\n\n <Button\n android:id="@+id/stop"\n android:layout_width="50dp"\n android:layout_height="50dp"\n android:layout_gravity="center"\n android:layout_weight="1"\n android:gravity="center"\n android:text="S" />\n</LinearLayout>\n
\nStyle.xml file
\n <resources>\n <!-- Base application theme. -->\n <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">\n <!-- Customize your theme here. -->\n <item name="colorPrimary">@color/colorPrimary</item>\n <item name="colorPrimaryDark">@color/colorPrimaryDark</item>\n <item name="colorAccent">@color/colorAccent</item>\n </style>\n\n</resources>\n
\nHow can I remove the extra space in Action Bar..?
\n","author":{"@type":"Person","name":"Real Tech Hacks"},"upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"If you want more customization on ActionBar, Use the ToolBar as an Actionbar which is more customizable than the default ActionBar.
\n","author":{"@type":"Person","name":"Venkat"},"upvoteCount":2}}}Reputation: 367
I'm new to android development and I am designing an app in which I use a custom Action Bar from a layout xml file. I had done with the following code and successfully got the layout into action bar. But the problem I am getting is extra space on left and right side of the Action Bar.
I'm using the following codes.
// java code
public class SimpleQns extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questions);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_qns);
//other codes for app }
xml layout file with name actionbar_qns.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="5"
android:background="@drawable/actionbar_qns"
android:padding="0dp"
android:layout_margin="0dp">
<Button
android:id="@+id/play"
android:layout_width="50dp"
android:layout_weight="1"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="P"
/>
<TextView
android:id="@+id/tv_actionbar_questions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_gravity="center"
android:gravity="center"
android:text="Simple Questions"
android:textColor="@color/white"
android:textSize="20sp" />
<Button
android:id="@+id/stop"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="S" />
</LinearLayout>
Style.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
How can I remove the extra space in Action Bar..?
Upvotes: 1
Views: 573
Reputation: 404
If you want more customization on ActionBar, Use the ToolBar as an Actionbar which is more customizable than the default ActionBar.
Upvotes: 2
Reputation: 847
ActionBar
contains a default padding in itself. Add this line to your ActionBar
xml to remove the default padding:
android:padding="0dp"
Upvotes: 0