Android Toolbar Three questions: Modify the left arrow color, how to modify the right side and toolbar in the child activity to add a 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?

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

[HTML]View PlainCopyprint?
  1. <item name="Actionoverflowbuttonstyle"> @style/overflowbuttonstyle</Item >
  2. <style name= "overflowbuttonstyle" parent= "@android: Style/widget.actionbutton.overflow ">
  3. <item name="android:src"> @drawable/float_button</Item>
  4. </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 .

[HTML]View PlainCopyprint?
  1. Getsupportactionbar (). Setdisplayhomeasupenabled (True);
  2. Want to respond to this return time. In fact, it is onoptionsitemselected () through android.r.id.home monitoring to get
  3. <pre name="code" class="java"> @Override
  4. public boolean onoptionsitemselected (MenuItem item) {
  5. if (item.getitemid () = = Android. R.id.home) {
  6. Onbackpressed ();
  7. }
  8. return true;
  9. }

[HTML]View PlainCopyprint?
    1. 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.
    2. Add activity to add the return button to the Androidmanifest.xml in the toolbar property
    3. Android:parentactivityname= "Com.example.myfirstapp.MainActivity"

[HTML]View PlainCopyprint?
  1. <application ... >
  2. ...
  3. <!--the main/home activity (it has no parent activity)--
  4. <activity
  5. android:name="com.example.myfirstapp.MainActivity" ... >
  6. ...
  7. </Activity>
  8. <!--A Child of the main activity--
  9. <activity
  10. android:name="com.example.myfirstapp.DisplayMessageActivity"
  11. android:label="@string/title_activity_display_message"
  12. android:parentactivityname="com.example.myfirstapp.MainActivity" >
  13. <!--Parent activity Meta-data to support 4.0 and lower-
  14. <meta-data
  15. android:name="Android.support.PARENT_ACTIVITY"
  16. android:value="com.example.myfirstapp.MainActivity" />
  17. </Activity>
  18. </Application>

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

[HTML]View PlainCopyprint?
    1. @Override
    2. public void OnCreate (Bundle savedinstancestate) {
    3. ...
    4. Getactionbar (). Setdisplayhomeasupenabled (True);
    5. }

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

Related Article

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.