Showing posts with label ui. Show all posts
Showing posts with label ui. Show all posts

September 5, 2011

[SOLVED] Chrome: How to change the default language (UI) in chrome

Normally you should find this option in "Under the Hood" tab but if have no such option do type
chrome://settings/languages

in to address bar and choose your preferred UI language.

then you must restart your Google Chrome Browser

 

Tested with chrome v13.0.782.220 m and v15.0.871.1 canary

November 21, 2010

[SOLVED] How to create Alert Dialog?

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                MyActivity.this.finish();
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
       });
AlertDialog alert = builder.create();
alert.show();

Source: developer.android.com

November 20, 2010

[SOLVED] Android: When the soft keyboard pops up, the EditText is invisible

Just add android:windowSoftInputMode="adjustPan" for your activity in manifest file
<activity android:name="SampleActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan" >
...
</activity>

Source: stackoverflow.com

Documentation: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Tutorial: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html

November 16, 2010

[SOLVED] Android - Arrange two buttons next to each other and to center them horizontally.

Arrange two buttons next to each other and to center them horizontally.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
    android:background="@android:drawable/bottom_bar" android:paddingLeft="4.0dip"
    android:paddingTop="5.0dip" android:paddingRight="4.0dip"
    android:paddingBottom="1.0dip" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/TextView01">
    <Button android:id="@+id/allow" android:layout_width="0.0dip"
        android:layout_height="fill_parent" android:text="Allow"
        android:layout_weight="1.0" />
    <Button android:id="@+id/deny" android:layout_width="0.0dip"
        android:layout_height="fill_parent" android:text="Deny"
        android:layout_weight="1.0" />
</LinearLayout>

 

Source: stackoverflow.com

July 17, 2010

[SOLVED]How customize/extend/ Spinner

You will need to take control over what goes into the ListView and
Spinner. I have not experimented with these techniques on Spinner, but
on ListView, you will need to override getView() (on ArrayAdapter) or
newView() and bindView() (on CursorAdapter).
Here is a free excerpt from one of my books that demonstrates the technique:

http://commonsware.com/Android/excerpt.pdf

In your case, you would use your Typeface object to update the font used
by the TextView widgets in your rows.

In principle, you could do this via a wrapping adapter -- this would be
more reusable but a bit slower. I have an AdapterWrapper base class here:

http://github.com/commonsguy/cwac-adapter

and some projects that use it here:

http://github.com/commonsguy/cwac-endless
http://github.com/commonsguy/cwac-thumbnail


You also need to override getDropDownView().

Source: How to change the Typeface of ListView and Spinner - Android Beginners Google Groups.

May 23, 2010

[SOLVED] Show web pages in Activity -Hello, WebView

WebView allows you to create your own web browser Activity. In this tutorial, we'll create a simple Activity that can view web pages.

Source: Hello, WebView | Android Developers.

May 5, 2010

[SOLVED] Android: How to stress/test your app with random streams of user events

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.


$ adb shell monkey -p your.package.name -v 500



UI/Application Exerciser Monkey Android Developers.

May 1, 2010

[SOLVED] Error on creating custom dialog

> Use dialog = new Dialog(this);
> instead of
> dialog = new Dialog(getApplicationContext());


private void showAbout() {
showDialog(DIALOG_ABOUT_ID);
}

protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_ABOUT_ID:
dialog = new Dialog(this);

dialog.setContentView(R.layout.about);
dialog.setTitle("Custom Dialog");
dialog.setOwnerActivity(this);

TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_contact_picture);

break;
// case DIALOG_GAMEOVER_ID:
// // do the work to define the game over Dialog
// break;
default:
dialog = null;
}
return dialog;
}






Source: Custom Dialog - Android Developers | Google Groups.

[SOLVED]Android: How to Make an Activity Fullscreen



  1. public class FullScreen extends Activity {

  2. @Override

  3. public void onCreate(Bundle savedInstanceState) {

  4. super.onCreate(savedInstanceState);


  5. requestWindowFeature(Window.FEATURE_NO_TITLE);

  6. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

  7. WindowManager.LayoutParams.FLAG_FULLSCREEN);


  8. setContentView(R.layout.main);

  9. }

  10. }




Source: Android Snippets: How to Make an Activity Fullscreen.

April 29, 2010

[SOLVED] Android: Convert dip to px.


It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is inTypedValue.applyDimension()Here's an example of how to convert dips to px in code:



// Converts 14 dip into its equivalent px
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());



Source: Does setWidthint pixels use dip or px? - Stack Overflow.

[SOLVED] Android: Using Custom Fonts


Android comes with 3 fonts (Sans, Serif, Monospace) which can be accesed using android:typeface="FONT_NAME". But most of the times you would want to use your own fonts instead of the stock ones. Android provides an "assets" folder where you can put your TTF font files and access them from within the code.



There are two ways of doing this,



1. Assign the Typeface object to TextView,



2. Paint the Typeface on screen Canvas.





Method 1 - Assigning Typeface object to TextView



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

TextView bauhs = null,chiller=null,broadw=null,joker=null ;
Button mag=null;

setFont(bauhs, "fonts/BAUHS93.TTF", R.id.bauhs);

setFont(broadw, "fonts/BROADW.TTF", R.id.broadw);

setFont(chiller, "fonts/CHILLER.TTF", R.id.chiller);

setFont(joker, "fonts/JOKERMAN.TTF", R.id.joker);

setFont(mag, "fonts/MAGNETOB.TTF", R.id.magneto);

}

void setFont(TextView name, String path, int res)
{
name=(TextView)findViewById(res);
Typeface font = Typeface.createFromAsset(this.getAssets(), path);

name.setTypeface(font);

}


- "Typeface" is the class for handling fonts.


- The createFromAsset() method is used to specify the font path.


font object is assigned to the TextView name



Method 2 - Drawing the font on screen canvas



@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new FontView(this));
}

private static class FontView extends View
{
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Typeface mFace;

public FontView(Context context)
{
super(context);

// mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/MAGNETOB.TTF");

mPaint.setTextSize(34);
mPaint.setColor(Color.WHITE);
}

@Override
protected void onDraw(Canvas canvas)
{
canvas.drawColor(Color.BLACK);

drawFont(canvas, "fonts/BAUHS93.TTF", 50, "Bauhaus 93");

drawFont(canvas, "fonts/BROADW.TTF", 150, "Broadway");

drawFont(canvas, "fonts/CHILLER.TTF", 250, "Chiller");

drawFont(canvas, "fonts/JOKERMAN.TTF", 350, "Jokerman");

}

void drawFont(Canvas canvas, String path, int y, String name)
{
mFace = Typeface.createFromAsset(getContext().getAssets(),path);

mPaint.setTypeface(mFace);
canvas.drawText(name, 30, y, mPaint);

}
}


- We need to extend the View class to access and override the onDraw() method.



- A Paint object is created which allows us to set the font size and color.



- The TypeFace object mFace is assigned to mPaint which is drawn on screen using the drawText().



drawText() takes 3 parameters, the text to be painted, its X-Y location and the Paint object.





Note: There is a difference between arial.ttf and ARIAL.TTF . If it ARIAL.TTF in your /assets folder and arial.ttf in your code, it will not work.

So if you have set the path correct but still wondering why the font is not being displayed, check this naming.


Source: Using Custom Fonts - ModMyGPhone Wiki.

April 11, 2010

[SOLVED]How to determine screen size programmatically

@Override
public void onCreate(Bundle icicle) {
. . .
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
.

How to determine screen resolution programmatically - Android Developers Google Groups.

April 3, 2010

[SOLVED] Do not show soft keyboard on Activiry start

Just put windowsSoftInputMode attribute in your Manifest

 <activity name="EditContactActivity"
android:windowSoftInputMode="stateHidden">
...
</activity>

Android Developers Blog: Updating Applications for On-screen Input Methods.

March 21, 2010

[SOLVDED] Android: Create custom buttons, Image & Text-Only

This very simple tutorial will add to your Android UI (user interface) development arsenal. How? Buttons that display as simple text or as images are basic elements of any application. By following the two steps below, these buttons can be easily created with Google’s Android by simply extending the current Button and ImageButton classes.

...

You can download the source to see for yourself.

Source: Android Tutorial.

February 28, 2010

[SOLVED] Android: Dynamically change Options Menu Items








import android.app.Activity;








02import android.os.Bundle;








03import android.view.Menu;








04import android.view.View;








05import android.view.View.OnClickListener;








06import android.widget.Button;








07








08/**








09 * Class which shows how to change dynamically options menu items








10 * @author FaYnaSoft Labs








11 */








12public class Main extends Activity {








13








14 private Button clickBtn;








15 private boolean isChangedStat = false;








16 private static final int MENUITEM = Menu.FIRST;








17








18 @Override








19 public void onCreate(Bundle savedInstanceState) {








20 super.onCreate(savedInstanceState);








21 setContentView(R.layout.main);








22 clickBtn = (Button) findViewById(R.id.click);








23 clickBtn.setText("Click me");








24 clickBtn.setOnClickListener(new OnClickListener() {








25








26 @Override








27 public void onClick(View v) {








28 if (isChangedStat) {








29 isChangedStat = false;








30 } else {








31 isChangedStat = true;








32 }








33 }








34 });








35 }








36








37 @Override








38 public boolean onPrepareOptionsMenu(Menu menu) {








39 menu.clear();








40 if (isChangedStat) {








41 menu.add(0, MENUITEM, 0, "True");








42 } else {








43 menu.add(0, MENUITEM, 0, "False");








44 }








45 return super.onPrepareOptionsMenu(menu);








46 }








47}


Dynamically change Options Menu Items in Android The Developers Info.