Wednesday, July 9, 2014

WebView Unicode Support

mWebView.loadDataWithBaseURL(null, "தமிழில் கணினி", "text/html", "utf-8", null);
OR
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");

Tuesday, July 8, 2014

Load Image from URL

Use the following code to display the picture in ImageView,
URL url = new URL("http://www.vijaynetwork.com/vijay_top_logo.jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);

Wednesday, June 4, 2014

How to open a new layout after button click in android

Use the below code,

How to write static HTML code in WebView control

Apply the below code,

webView = (WebView) findViewById(R.id.webView1);
webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setBuiltInZoomControls(true);
webViewSettings.setPluginState(PluginState.ON);
webView.getSettings().setJavaScriptEnabled(true);
String data="<h1>welcome to Android example..Write your own HTML code here..</h1><br>";
webView.loadData(data, "text/html","utf-8");

Thursday, May 29, 2014

How to enable Java Script in WebView

       myWebView = (WebView) findViewById(R.id.WebView1);
       WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

How to Zoom out WebView content

        myWebView.setInitialScale(60);
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);

How to load a web page in webview control

WebView myWebView;      

myWebView = (WebView) findViewById(R.id.WebView1);
myWebView.loadUrl("http://www.google.com");

Playing Ringtone

Saturday, April 26, 2014

Android Studio 0.5.1 - Install gradle 1.10

After installing Android Studio 0.5.1, you may get the below message,

The project is using an unsupported version of Gradle. Please use version 1.10


Solution for this:

Modify the gradle-wrapper.properties

distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
and your build.gradle

compileSdkVersion 19
buildToolsVersion "19.0.1"

running:./gradlew clean assemble in the terminal


Tuesday, March 11, 2014

How to add space between each controls( buttons, text box )..

There is simple way to add space between controls( buttons, text boxes..etc..) in an linear layout. Add the following attribute in the controls,

<Button
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
/>

This will allow 15dp space above the button. Likewise you can give space between each controls. You can use the following attributes too,

android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"

Sunday, January 26, 2014

Android activity title background color/image change


For changing Title bar background, add the following code in the activite's onCreate() function,

 ActionBar bar = getActionBar();
//for color
 //bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#DDAAD")));
//for image
 bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_bg3));
bar.setTitle("add your own title here");

For changing the Title bar title's color,

In the onCreate() Function,

this.setTitleColor(getResources().getColor(R.color.black));

Saturday, January 18, 2014

Android Button Click Event

There are three ways to do it,

First Method,

In the onCreate function,


Button button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new OnClickListener()
    {
      public void onClick(View v)
      {
         ImageView iv = (ImageView) findViewById(R.id.imageview1);
         iv.setVisibility(View.VISIBLE);
      }
    });

Second Method,

Import the following package,
import android.view.View.OnClickListener;

In onCreate method add the following Listener,

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();

}

Implement the Listener,

 
public void addListenerOnButton() {
 
button = (Button) findViewById(R.id.button1);
 
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent browserIntent = 
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.vijaynetwork.com"));
startActivity(browserIntent);
}
});

Third Method,

<Button
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/self_destruct"

     android:onClick="displayMap" />

when a user clicks the button, the Android system calls the activity's displayMap(View) function.

And the function declaration would be,

public void displayMap(View myview)
{
//made your own code for button click
}