Draw circle Android basic example
Canvas, drawCircle(), Paint, onDraw(), setStrokeWidth(), setStyle()
public class MainActivity 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) {
canvas.drawColor(Color.CYAN);
Paint p = new Paint();
// smooths
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(4.5f);
// opacity
//p.setAlpha(0x80); //
canvas.drawCircle(50, 50, 30, p);
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
Eclipse make own color of toolbars, windows, status bar etc.
https://github.com/jeeeyul/eclipse-themes/wiki/Alternative-Install
https://github.com/jeeeyul/eclipse-themes/wiki/Alternative-Install
Get key by value from Map Java Android example
MainClass.java
MainClass.java
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
, "three;drei", "four;vier" };
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);
}
}
if (map.containsValue("zwei")) {
Set<String> references = getKeysByValue(map, "zwei");
Iterator<String> it = references.iterator();
while (it.hasNext()) {
String key = (String) it.next();
String value = map.get(key);
System.out.println(key + " = " + value);
}
}
}
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
Set<T> keys = new HashSet<T>();
for (Entry<T, E> entry : map.entrySet()) {
if (entry.getValue().equals(value)) {
keys.add(entry.getKey());
}
}
return keys;
}
}
/*
two = zwei
two sets of = zwei
*/
"id cannot be resolved or is not a field” error
If you copy project to workspace or some code from other project you can get this error.
Try remove or add import your R file:
Check xml files.
Clean project by menu Project-Clean
Maybe you have to create new project end copy old source files to new project folders.
If you copy project to workspace or some code from other project you can get this error.
Try remove or add import your R file:
import com.example.app.R
Check xml files.
Clean project by menu Project-Clean
Maybe you have to create new project end copy old source files to new project folders.
Toast in Android application is equivalent of Alert in JavaScript or MessageBox in WinApi.
// Toast android.widget.Toast.makeText(Context context, CharSequence text, int duration)
// public static Toast makeText (Context context, CharSequence text, int duration)
Toast.makeText(getApplicationContext(), "Hello world!",
Toast.LENGTH_SHORT).show();
Android Studio ADB restart mobile device from USB every time if RUN of DEBUG button pressed
Try to close the mobile application on your device completely before starting again from Android Studio.Close every fragment.
The problem occurs when the application has multiple fragments.
Date: 13.07.2020 - 08:23
Editace: 2013-12-09 13:11:26
Počet článků v kategorii: 396
Url:draw-circle-android-basic-example