todo: button to change colors input with button to change colors textview font?
write file example read file example
android emulator tweak - file write
First always ensure you've got an emulator with the right platform level, it's probably best to use 2.1 for all defaults as it will ensure the highest level of compatibility. Additionally don't forget that after ADT /SDK plugin install:
- Eclipse -> Window -> AVD Manager -> New AVD (include a virtual SD card!)
- Also, right click on the Project -> Run As -> Run Configuration
- Android Application -> Notepadv1 ... Target tab should be the android virtual device with 2.1 API and SD card
package kittyandbear.net;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
import android.graphics.Color;
public class Notepadv1Activity extends Activity
{
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
TextView tv = new TextView( this ); // http://developer.android.com/reference/android/widget/TextView.html
setTextColors( tv );
if( isExternalStorageWriteable() )
{
tv.setText( "I can write a file!" );
}
else
{
tv.setText( "I can not write a file =[" );
}
setContentView( tv );
}
- private boolean isExternalStorageWriteable( )
{
boolean result = false;
String state = Environment.getExternalStorageState();
// http://developer.android.com/reference/android/os/Environment.html
if( state.equals( Environment.MEDIA_MOUNTED ) && !state.equals( Environment.MEDIA_MOUNTED_READ_ONLY ) )
{ result = true;
}
return result;
}
private void setTextColors( TextView tv )
{
int bgcolor = Color.parseColor( "#D3D3D3" );
int fgcolor = Color.parseColor( "#000000" );
tv.setBackgroundColor( bgcolor );
tv.setTextColor( fgcolor );
}
} //end class
// import android.view.Menu; import android.view.MenuItem;
/*
@Override
public boolean onCreateOptionsMenu( Menu menu )
{
return super.onCreateOptionsMenu( menu );
}
@Override
public boolean onOptionsItemSelected( MenuItem item )
{
return super.onOptionsItemSelected( item );
}
*/