{"id":2404,"date":"2017-04-04T12:43:25","date_gmt":"2017-04-04T12:43:25","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2404"},"modified":"2017-04-19T14:22:24","modified_gmt":"2017-04-19T14:22:24","slug":"how-to-change-the-text-and-the-color-using-java-code","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-change-the-text-and-the-color-using-java-code\/","title":{"rendered":"How to change the text and the color using Java code"},"content":{"rendered":"<p>In this tutorial how to and how to change color and text by using java code is shown.<\/p>\n<p>Code:<\/p>\n<p>activity_main.xml<\/p>\n<p>&lt;RelativeLayout xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221;<br \/>\nxmlns:tools=&#8221;http:\/\/schemas.android.com\/tools&#8221;<br \/>\nandroid:layout_width=&#8221;match_parent&#8221;<br \/>\nandroid:layout_height=&#8221;match_parent&#8221;<br \/>\nandroid:paddingBottom=&#8221;@dimen\/activity_vertical_margin&#8221;<br \/>\nandroid:paddingLeft=&#8221;@dimen\/activity_horizontal_margin&#8221;<br \/>\nandroid:paddingRight=&#8221;@dimen\/activity_horizontal_margin&#8221;<br \/>\nandroid:paddingTop=&#8221;@dimen\/activity_vertical_margin&#8221;<br \/>\ntools:context=&#8221;.MainActivity&#8221; &gt;<\/p>\n<p>&lt;TextView<br \/>\nandroid:id=&#8221;@+id\/textView1&#8243;<br \/>\nandroid:layout_width=&#8221;wrap_content&#8221;<br \/>\nandroid:layout_height=&#8221;wrap_content&#8221;<br \/>\nandroid:text=&#8221;@string\/hello_world&#8221; \/&gt;<\/p>\n<p>&lt;\/RelativeLayout&gt;<\/p>\n<p>MainActivity.java<\/p>\n<p>package com.example.demo;<\/p>\n<p>import android.os.Bundle;<br \/>\nimport android.app.Activity;<br \/>\nimport android.graphics.Color;<br \/>\nimport android.view.Menu;<br \/>\nimport android.widget.TextView;<\/p>\n<p>public class MainActivity extends Activity {<\/p>\n<p>TextView tv1;<\/p>\n<p>@Override<br \/>\nprotected void onCreate(Bundle savedInstanceState) {<br \/>\nsuper.onCreate(savedInstanceState);<br \/>\nsetContentView(R.layout.activity_main);<br \/>\ntv1=(TextView)findViewById(R.id.textView1);<br \/>\ntv1.setText(&#8220;Hello Friends!&#8221;);<br \/>\ntv1.setTextColor(Color.GREEN);<br \/>\n}<br \/>\n@Override<br \/>\npublic boolean onCreateOptionsMenu(Menu menu) {<br \/>\n\/\/ Inflate the menu; this adds items to the action bar if it is present.<br \/>\ngetMenuInflater().inflate(R.menu.main, menu);<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/youtu.be\/zXrTEXTI9rM\">https:\/\/youtu.be\/zXrTEXTI9rM<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how to and how to change color and text by using java code is shown. Code: activity_main.xml &lt;RelativeLayout xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221; xmlns:tools=&#8221;http:\/\/schemas.android.com\/tools&#8221; android:layout_width=&#8221;match_parent&#8221; android:layout_height=&#8221;match_parent&#8221; android:paddingBottom=&#8221;@dimen\/activity_vertical_margin&#8221; android:paddingLeft=&#8221;@dimen\/activity_horizontal_margin&#8221; android:paddingRight=&#8221;@dimen\/activity_horizontal_margin&#8221; android:paddingTop=&#8221;@dimen\/activity_vertical_margin&#8221; tools:context=&#8221;.MainActivity&#8221; &gt; &lt;TextView android:id=&#8221;@+id\/textView1&#8243; android:layout_width=&#8221;wrap_content&#8221; android:layout_height=&#8221;wrap_content&#8221; android:text=&#8221;@string\/hello_world&#8221; \/&gt; &lt;\/RelativeLayout&gt; MainActivity.java package com.example.demo; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { TextView tv1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1=(TextView)findViewById(R.id.textView1); tv1.setText(&#8220;Hello Friends!&#8221;); tv1.setTextColor(Color.GREEN); } @Override public boolean onCreateOptionsMenu(Menu menu) { \/\/ Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } &nbsp;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[65,69],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2404"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2404"}],"version-history":[{"count":2,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2404\/revisions"}],"predecessor-version":[{"id":2411,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2404\/revisions\/2411"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}