Font Family change on View dynamically Android Example
TypeFace, setTypeface, font, font family, array of String, Button create dynamically
@Override
protected void onStart() {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
48,
55
);
Typeface typeFace = Typeface.MONOSPACE;
String [] ar = {"A","B","C","D","E","F","G","H","J","K"};
for (int i = 0; i < ar.length; i++) {
Button buttonView = new Button(this);
buttonView.setText(Html.fromHtml("<b>"+ar[i]+"</b>"));
buttonView.setTextColor(Color.BLUE);
buttonView.setTextSize(27.f);
buttonView.setTypeface(typeFace,Typeface.BOLD);
buttonView.setOnClickListener(mThisButtonListener);
if(i%2==0)
mLayoutButtons.addView(buttonView, p);
else
mLayoutButtonsNextRow.addView(buttonView, p);
_listOfButtons.add(buttonView);
}
super.onStart();
}
//////// xml file
<TextView
android:id="@+id/text01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:fontFamily="Arial"
/>
396LW NO topic_id
AD
Další témata ....(Topics)
Map TreeMap add key value pair get find pair by key Java Android example.
MainClass.java
MainClass.java
import java.util.Map;
import java.util.TreeMap;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };
Map<String, String> map = new TreeMap<String, String>();
for(String s: arrayOfString){
String[] array = s.split(";");
String sKey ="", sValue="";
if(array.length > 1){
sKey = array[0]; sValue = array[1];
map.put(sKey, sValue);
}
}
// check if key exists
if( map.containsKey("two")){
System.out.print("two = " + map.get("two"));
}
}
}
/*
two = zwei
*/
Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with `checkPermission`) or explicitly handle a potential `SecurityException`
try {
// your code for example:
// LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Criteria criteria = new Criteria();
// provider = locationManager.getBestProvider(criteria, false);
// locationManager.requestLocationUpdates(provider, 400, 1, this);
} catch (SecurityException e) {
e.printStackTrace();
}
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.GREEN);
Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(b);
c.drawRect(0, 0, 200, 200, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
paint.setTextSize(40);
paint.setTextScaleX(1.f);
paint.setAlpha(0);
paint.setAntiAlias(true);
c.drawText("Your text", 30, 40, paint);
paint.setColor(Color.RED);
canvas.drawBitmap(b, 10,10, paint);
}
}
}
Drawable dr = getResources().getDrawable(R.drawable.algebra);
int h = dr.getIntrinsicHeight();
int w = dr.getIntrinsicWidth();
Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.algebra);
int _nWidth = ball.getWidth();
int _nHeight = ball.getHeight();
C:\documents\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs
Editace: 2013-03-03 21:21:12
Počet článků v kategorii: 396
Url:font-family-change-on-view-android-example