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
chrome://settings/languages
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();
<activity android:name="SampleActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan" >
...
</activity>
<?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>
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
WebView
allows you to create your own web browser Activity. In this tutorial, we'll create a simple Activity that can view web pages.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
TextView t=(TextView) findViewById(android.R.id.title);
t.setGravity(Gravity.CENTER_HORIZONTAL);
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());
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.
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
@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.
@Override
public void onCreate(Bundle icicle) {
. . .
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
.
<activity name="EditContactActivity"
android:windowSoftInputMode="stateHidden">
...
</activity>
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.
import
android.app.Activity;
02
import
android.os.Bundle;
03
import
android.view.Menu;
04
import
android.view.View;
05
import
android.view.View.OnClickListener;
06
import
android.widget.Button;
07
08
/**
09
* Class which shows how to change dynamically options menu items
10
* @author FaYnaSoft Labs
11
*/
12
public
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
}