How to change the hint text color in android?

Hello all..

This simple example will show you how to change the hint text color in android

Here is the java code to simply do this.

youredittext.setHint(Html.fromHtml("<font color='#FF0000'>Hello</font> "));

here is a sample project to view the difference.

This is the contents of the main java file.

package com.coderzheaven.pack;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.EditText;

public class HintColorDemoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          EditText ed = (EditText)findViewById(R.id.editText1);
          ed.setHint("Hello ");

          EditText ed2 = (EditText)findViewById(R.id.editText2);
          ed2.setHint(Html.fromHtml("<font color='#FF0000'>Hello</font> "));
     }
}

The main.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:orientation="vertical" >

     <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/hello" />

     <EditText
          android:id="@+id/editText1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" >

          <requestFocus />
     </EditText>

     <EditText
          android:id="@+id/editText2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" >
     </EditText>
</LinearLayout>


Here I am setting a read color to the second edittext hint.
See the screenshot.

Please leave your comments if you found this useful.

TextView with link in ANDROID…….

Hi all…….

All of you may be familiar with TextViews in ANDROID.
But how many of you know that we have have html as text in a textView. This post is a simple example to show this.

Create a fresh project and copy this code to the main java file.

package com.coderzheaven;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

public class TextViewLinkDemo extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = (TextView) findViewById(R.id.tv);
        tv.setText( Html.fromHtml("<b>This is a textView with a link </b>  " +
                    " <br /> <a href="http://www.coderzheaven.com">Coderzheaven</a> " +
                    "created in the Java source code using HTML."));
         tv.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

The main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
	android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>

The AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.coderzheaven"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TextViewLinkDemo"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Link in TextView Demo

Link in TextView Demo

How to Disable Right Click on HTML page using jQuery ?

Hi,

In some special cases you may need to disable the Right Click option on HTML page you are using.
An easy way to do it using jQuery is follows. Use the following code in the HTML page where you want to disable Right Click.

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

:)

Load a webpage in Adobe AIR

This example shows how to load a webpage inside Adobe AIR,
For this first you have to place an HTML control in your design for loading the html content.
Create an page “index.html” inside the application directory of your current project and add some Html content to it.
After that copy the following code to your source file.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
      private function init():void
      {
         this.stage.nativeWindow.maximize();    // maximizes your window.
         html.location="index.html";            // loads the html content in the html text area.
      }
]]>
</mx:Script>
<mx:HTML id="html"     width="100%" height="100%" />
</mx:WindowedApplication>

Please leave your comments on this post…….

How to add more than One HTML Document in a single Browser ?

Hi…

There may arise certain situations where you need to include more than one HTML document in the same browser.

But how?

It’s simple. It’s by using FRAMES of HTML.
FRAMES can be included inside FRAMESET.

Let’s see an example.

<frameset cols="200,400">
   <frame src="http://www.coderzheaven.com" />
   <frame src="http://www.google.com" />
</frameset>

This will create two column frames in the browser with www.coderzheaven in one frame with 200 pixels, and www.google.com in another frame with 400 pixel.

You can also give cols percentage as well. Like cols=”25%,75%”.
:)

Hide and Show a Text Using jQuery – Example

With jQuery manipulation of HTML & CSS can be done very easily.
Here we are going to show how to Hide a line of text using jQuery & Show it back also.
Let’s code speak first….


<html>
<head>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

$(document).ready(function(){
$("#hideButton").click(function(){
$("p").hide();
});

$("#showButton").click(function(){
$("p").show();
});
});
</script>

</head>
<body>

<p>Hey! Click 'Left', I will vanish! Click 'Right', I will be back!</p>

<button id="hideButton">Left</button>
<button id="showButton">Right</button>
</body>
</html>

Note : Download and put ‘jquery.js’ on your working folder before trying out!

What these code did?

Here we have one line text, html paragraph. Two buttons ‘Left’ & ‘RIght’ and whose id’s

are ‘hideButton’ & ‘showButton’ respectively.

jQuery code identifies which button we clicked using the button id’s mentioned above and

apply the hide() or show() function to the html paragraph p.
:) 

How do you call an actionscript function from a html page and viceversa. How to you access the actionscript variable function from an HTML page in actionscript.

The following code helps you to do this.
Save the following  code as am .mxml file

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init()">
    <mx:Script>
    <![CDATA[
        private var calledFromJSHandlerFunction:Function = calledFromJSHandler;
        private function init():void{
            html.addEventListener(Event.HTML_DOM_INITIALIZE, domInitialized);
            html.location = "start.html";
        }
        private function domInitialized(event:Event):void{
            html.htmlLoader.window.calledFromJSHandlerFunction = calledFromJSHandlerFunction;
        }
        private function calledFromJSHandler():void {
            mx.controls.Alert.show("ActionScript called from JavaScript", "Alert");
        }
        private function doHTMLAlert( ):void {
            html.htmlLoader.window.calledFromAS();
        }
    ]]>
    </mx:Script>
    <mx:Button id="alertBtn" label="Call JavaScript from ActionScript"
        click="doHTMLAlert()" x="137" y="10"/>
    <mx:HTML id="html" x="137" y="40" width="339"/>
    <mx:Label x="10" y="12" text="Normal MXML Button"/>
    <mx:Label x="28" y="38" text="HTML component"/>
</mx:WindowedApplication>

The html file start.html

<html>
    <script language="Javascript">
        function calledFromAS() {
            alert('Hello from ActionScript');
        }
        </script>
    <body>
        <input type="button"
            value="Call ActionScript from JavaScript"
            onclick="calledFromJSHandlerFunction()" />
        <br />
        <input type="button"
            value="Normal JavaScriptAlert"
            onclick="alert('Hello from JavaScript')">
    </body>
</html>

what is the difference between CSS and XSL?

CSS = Style Sheets for HTML

HTML uses predefined tags, and the meaning of each tag is well understood.

The table tag in HTML defines a table – and a browser knows how to display it.

XSL = Style Sheets for XML

XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood.

A table tag could mean an HTML table, a piece of furniture, or something else – and a browser does not know how to display it.

XSL describes how the XML document should be displayed!

XSL consists of three parts:

XSLT – a language for transforming XML documents
XPath – a language for navigating in XML documents
XSL-FO – a language for formatting XML documents