[JAVA] How to use ToolBar with super margin Part1 Set characters and change colors

This goal

--Set characters --Change the font color

Set characters in ToolBar

  1. First, place the ToolBar on top of the layout.

activity_main.xml



<android.support.v7.widget.Toolbar

android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:layout_alignParentTop="true" 
android:background="?attr/colorPrimary" 
android:minHeight="?attr/actionBarSize" 
android:theme="?attr/actionBarTheme"/> 
  1. Set the character

MainActivity.java


 @Override

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar=findViewById(R.id.toolbar); 
    toolbar.setTitle("Enter the character you want to set here"); 
    setSupportActionBar(toolbar); 
    } 

It is also possible to call the characters in String.xml by removing the double quotation marks in parentheses and setting it to [R.string. ○○].

If that doesn't work, you may have imported android.widget.toolbar !!!

In that case, you may try importing android.support.v7.widget.Toolbar, or set the minimum supported android version to API21.

Change the color of the characters set in ToolBar

I set the characters earlier, but now I will set the colors.

MainActivity.java


 @Override

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar=findViewById(R.id.toolbar); 
    toolbar.setTitle("Enter the character you want to set here"); 
    toolbar.setTitleTextColor(rgb(255,255,255));    
    setSupportActionBar(toolbar); 
    } 

The trick is to specify RGB instead of HTML color. The above is white, but you can set it to many other colors. Let's set it according to your preference. You can read from color.xml by setting [R.color. ○○]. This way you can use HTML color.

Finally

At first, you might think that ToolBar was easy for those who thought it was difficult. See you again! Then !!!

Author's Google+ Author's Twitter

Recommended Posts

How to use ToolBar with super margin Part1 Set characters and change colors
How to set up and use kapt
How to use RealSense with ubuntu 20.04 and ROS Noetic
How to use StringBurrer and Arrays.toString.
How to use EventBus3 and ThreadMode
How to use equality and equality (how to use equals)
How to use mssql-tools with alpine
[Rails] How to introduce kaminari with Slim and change the design
How to set and use profile in annotation-based Configuration in Spring framework
How to use OrientJS and OrientDB together
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
[Swift] How to connect TabBar with Storyboard Reference and also use NavigationController
How to use args :, environment :, env_file: and .env files with docker-compose command
How to set JAVA_HOME with Maven appassembler-maven-plugin
How to use substring and substr methods
How to use @Builder and @NoArgsConstructor together
How to set up computer vision for tracking images and videos with TrackingJs
How to use Eclipse on my PC with 32bit and 2GB of memory
How to use Swift's Codable Super personal memo
[Java] How to use FileReader class and BufferedReader class
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
[Ruby] How to use gsub method and sub method
How to use Java framework with AWS Lambda! ??
Note how to use Swift super basic TableView
How to use Segmented Control and points to note
How to use Java API with lambda expression
How to set up and operate jEnv (Mac)
Super easy way to use enum with JSP
How to use scope and pass processing (Jakarta)
How to build API with GraphQL and Rails
How to use nfs protocol version 2 with ubuntu 18.04
How to use docker compose with NVIDIA Jetson
How to use nginx-ingress-controller with Docker for Mac
[For super beginners] How to use autofocus: true
[Java] How to use Calendar class and Date class
How to set the retry limit of sidekiq and notify dead queues with slack
[Part 1] How to deploy Docker containers and static files with CircleCI + ECS + ECR + CloudFront
Summary of how to use the proxy set in IE when connecting with Java
How to change the action with multiple submit buttons
How to use Oracle JDK 9 EA with Travis CI
How to use Z3 library in Scala with Eclipse
Excel sheet and set Tab colors to rename Java
[Java] Refer to and set private variables with reflection
How to serialize and deserialize LocalDateTime type with GSON
How to use JDD library in Scala with Eclipse
[Beginner] How to use devise Change settings from introduction
How to install Gradle and Kotlin with SDKMAN (Mac)
Common problems with WSL and how to deal with them
[Linux] Easy commentary! How to check and change permissions
How to use and apply Java's JFrame / Canvas class
How to use GitHub for super beginners (team development)
How to add another project as Maven library with CircleCI and use it for build
Check how to set the timeout when connecting with Spring + HikariCP + MySQL and executing SQL
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging