Monday, November 25, 2013

How to override 'web site not found' message in webview control


Add the following code inside of 'onCreate(Bundle savedInstanceState)' function,

 locationview.setWebViewClient(new WebViewClient()
{
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
  {
locationview.loadUrl("file:///assets/error.html");

  }  });

The above URL will be load if the web page not found in the webview control.

Saturday, August 10, 2013

How to remove notification bar

Put this code in your onCreate() method,

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

How to remove title bar..

Put this in your onCreate() method.

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Thursday, September 6, 2012

Android - Screen Touch Event

Here is the example code to get X and Y axis while mobile screen get touched..
XML file,

<?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/touchView"
    android:background="#345"
    android:layout_weight="3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<TextView
    android:id="@+id/textView"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Touch Effect.."
    />
</LinearLayout>

Java Code,

package com.example.androidtouch;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class AndroidTouchActivity extends Activity {

    @Override
public void onCreate(Bundle savedInstanceState) 
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_android_touch);
   final TextView textView = (TextView)findViewById(R.id.textView);
   // this is the view on which you will listen for touch events
   final View touchView = findViewById(R.id.touchView);
   touchView.setOnTouchListener(new View.OnTouchListener() 
   {
   @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
      textView.setText("Touch coordinates : " +
       String.valueOf(event.getX()) + "x" + 
       String.valueOf(event.getY()));
                    return true;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
   {
    getMenuInflater().inflate(R.menu.activity_android_touch, menu);
    return true;
   }
}

Output,