Toolbar Three questions: Modify the left arrow color, how to modify the right side and toolbar in the child activity add the return arrow

Source: Internet
Author: User

1) How to change the color of the small arrow on the left.
2) How to change the color of the three points on the right and how to replace the three points with my own icon.

3) How to make the "trade list" of the 4 words in the center display.

As shown in the figure

First set theme to Appcompat.noactionbar.

(1) toolbar can be set Setnavigatetionicon, an icon will be passed in to replace the left-most small arrow, but you need to implement its own action.

(2) Add in your own theme definition

<item name= "Actionoverflowbuttonstyle" > @style/overflowbuttonstyle</item>
<style name= " Overflowbuttonstyle "parent=" @android: Style/widget.actionbutton.overflow ">

    <item name=" ANDROID:SRC " > @drawable/float_button</item>
</style><pre><code class= "Language-text" > You can change those three points. </code>
(3) It is my personal practice not to use settitle, but to insert a TextView in the toolbar XML definition and then set its layout_gravity to center, which is in the middle.
The other arrow shows the code.
Getsupportactionbar (). Setdisplayhomeasupenabled (true);
Want to respond to this return time. In fact, onoptionsitemselected ()
<pre name= "code" class= "Java" > @Override public through android.r.id.home
    monitoring Boolean onoptionsitemselected (MenuItem item) {
        if (item.getitemid () = = Android. R.id.home) {
            onbackpressed ();
        }
        return true;
    }

After entering a child activity from the mainactivity, how do you make a return arrow appear to the left of the toolbar and return to the mainactivity after clicking? It's really simple, just two lines of code.

Add activity to add the return button to the Androidmanifest.xml in the toolbar property
android:parentactivityname= "Com.example.myfirstapp.MainActivity"

<application ... > ...
    <!--the main/home activity (it has no parent activity)--
    <activity
        android:name= " Com.example.myfirstapp.MainActivity "...> ...
    </activity>
    <!--A Child of the main activity--
    <activity
        android:name= " Com.example.myfirstapp.DisplayMessageActivity "
        android:label=" @string/title_activity_display_message "
        android:parentactivityname= "Com.example.myfirstapp.MainActivity" >
        <!--Parent activity Meta-data To support 4.0 and lower-
        <meta-data
            android:name= "Android.support.PARENT_ACTIVITY"
            Android : value= "com.example.myfirstapp.MainActivity"/>
    </activity>
</application>


And then add a line of code to the program to implement the
	

@Override public
void OnCreate (Bundle savedinstancestate) {
    ...
    Getactionbar (). Setdisplayhomeasupenabled (true);




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.