Using Action Bar Android Development
I am new to android development. I am working on a small project, The title of the app is supposed to be in the center and a textview on the left side of the action bar. I would li
Solution 1:
Add Custom Toolbar to your Layout
<android.support.v7.widget.Toolbarandroid:id="@+id/custom_toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:popupTheme="@style/AppTheme.PopupOverlay"
><TextViewandroid:id="@+id/tv_edit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textStyle="bold"android:textColor="@color/white"android:text="Edit"
/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:padding="5dp"android:orientation="horizontal"
><TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textStyle="bold"android:textColor="@color/white"android:text="Movies"
/></LinearLayout></android.support.v7.widget.Toolbar>
and Add this Code to your Java Class , inside your onCreate()
Toolbar custom_toolbar= (Toolbar) findViewById(R.id.custom_toolbar);
setSupportActionBar(custom_toolbar);
Hope this works for you, best of luck....
Solution 2:
Your way is correct but please go through the Slidenerd Material design tutorial. You can create your own toolbar with your specification.Following site help you: Slidenerd toolbar tutorial
Solution 3:
Yes,perfect.
A small change can be instead of hiding the existing Action Bar you can replace it with your custom view( for now let us assume it is custom_actionbar.xml).your code goes like this :
ActionBarmActionBar= getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflatermInflater= LayoutInflater.from(this);
ViewmCustomView= mInflater.inflate(R.layout.custom_actionbar, null);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
Solution 4:
Add the below code . It will work.
ActionBaractionBar= getActionBar();
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflaterinflater= LayoutInflater.from(this);
Viewv= inflater.inflate(R.layout.action_bar_title, null);
TextViewtitleTextView= (TextView) v.findViewById(R.id.custom_action_bar_title);
titleTextView.setText("Title");
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(icon);
actionBar.setCustomView(v);
Solution 5:
I will recommend you to use toolbar api's provided in Lollipop version of android but with getSupportActionbar(), use this-
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
Post a Comment for "Using Action Bar Android Development"