Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday 29 November 2014

How to Make an Activity Fullscreen

This code makes the current Activity Full-Screen. No Status-Bar or anything except the Activity-Window!
 
public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Or you can do it via your AndroidManifest.xml file:

<activity android:name=".ActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
 
Read more...

Thursday 6 November 2014

Android: How to start another activity when click on item from spinner items




Spinner Spinner = (Spinner) findViewById(R.id.spinner);

Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onItemSelected(AdapterView<?> arg0, View view,
            int position, long row_id) {
        final Intent intent;
        switch(position){
            case 1:
                intent = new Intent(CurrentActivity.this, TargetActivity1.class);
                break;
            case 2:
                intent = new Intent(CurrentActivity.this, TargetActivity2.class);
                break;
// and so on 
// .....

        }
        startActivity(intent);

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

});
Read more...

Android: How to include mulitple Java Packages

Create a project having multiple packages.
And we want to integrate all these packages then there is only one way to do this. And here is the process:

You do not need any explicit inclusion of different packages in the manifest. To include activities from two different packages, say:
com.example.package1.Activity1
com.example.package2.Activity2
you can do the following:
<manifest package="com.example" . . . >
  <application . . .>
    <activity android:name=".package1.Activity1" . . . />
    <activity android:name=".package2.Activity2" . . . />
  </application>
</manifest>
Read more...

Android - How can I make a button flash/blink?

There are several, depending on what kind of flashing you mean. You can, for example, use alpha animation and start it as your button first appears. And when the user clicks button, in your OnClickListener just do clearAnimation().
Example:
public void onCreate(Bundle savedInstanceState) {
    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
    final Button btn = (Button) findViewById(R.id.your_btn);
    btn.startAnimation(animation);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            view.clearAnimation();
        }
    });
}
Read more...

How to create a blinking text in Android?

Here I am explaining two methods on how to create a blinking textview in Android.
One with the help of Animation class and other with a Logic.
package com.example.blinktext;
 
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        blinkText();
        //blinkText2();
    }
     
    private void blinkText(){
        final Handler handler = new Handler();
        new Thread(new Runnable() {
            @Override
            public void run() {
            int timeToBlink = 1000;    //in ms
            try{
                Thread.sleep(timeToBlink);
            }catch (Exception e) {
                 
            }
            handler.post(new Runnable() {
                @Override
                    public void run() {
                    TextView txt = (TextView) findViewById(R.id.tv);
                    if(txt.getVisibility() == View.VISIBLE){
                        txt.setVisibility(View.INVISIBLE);
                    }else{
                        txt.setVisibility(View.VISIBLE);
                    }
                    blinkText();
                }
                });
            }}).start();
   }
     
    public void blinkText2(){
        TextView myText = (TextView) findViewById(R.id.tv );
 
        Animation anim = new AlphaAnimation(0.0f, 1.0f);
        anim.setDuration(50); //You can manage the time of the blink with this parameter
        anim.setStartOffset(20);
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(Animation.INFINITE);
        myText.startAnimation(anim);
    }   
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}

Read more...