Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Create Bitmap with Linear Gradient Android example




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);
             paint.setColor(Color.BLUE);
            
            Shader mShader = new LinearGradient(0, 0, 100, 70, new int[] {
                    Color.RED, Color.GREEN, Color.BLUE },
                    null, Shader.TileMode.MIRROR);  // CLAMP MIRROR REPEAT
            Canvas c = new Canvas(b);
            paint.setShader(mShader);
            //c.drawCircle(60, 60, 30, paint);
            c.drawRect(0, 0, 200, 200, paint);
            canvas.drawBitmap(b, 10,10, paint);
		}

	}
}


linear gradient bitmap android example

397LW NO topic_id



Další témata ....(Topics)


319

Unable to execute dex: Multiple dex files define Eclipse Android | unable-to-execute-dex-multiple-dex-files-define-eclipse-android


Try each step separately:


  1. Restart Eclipse

  2. Clean project and rebuild

  3. Create a new project and try it if the problem persists, if no move copy project to other folder, delete project from workspace , create new project same name and copy java, xml etc. files to new project

  4. Close Eclipse, backup folder c:\Users\myName\workspace\.metadata and delete it. Restart Eclipse try again import project to workspace


  5. Re-installing the Android Developer Tools


  6. Re-installing Eclipse - rename old folder with Android to Android_old, create new folder C:\Program Files\Android and copy new Eclipse with sdk into new folder


  7. Created a new project importing from the file system


  8. Created a new project from subversion



390

Call requires permission which may be rejected by user | call-requires-permission-which-may-be-rejected-by-user


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();
        }


317

Importing google-play-service library project to workspace issue | importing-google-play-service-library-project-to-workspace-issue


Try two way in Eclipse IDE:

1.) Import the library project into your Eclipse workspace.
Click File > Import,
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
If project not visible with checkbox try next step as see below.

2.) Click
File > New > Other
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
160

Linkify text link url in TextView text Android example | linkify-text-link-url-in-textview-text-android-example


Example from SDK C:\Program Files\Android\android-sdk-windows\samples\android-10\ApiDemos\src\com\example\android\apis\text\Link.java
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"

// res/values/strings.xml
<string name="link_text_auto"><b>text1:</b> This is some text.  In
      this text are some things that are actionable.  For instance,
      you can click on //www.google.com and it will launch the
      web browser.  You can click on google.com too.  And, if you
      click on (415) 555-1212 it should dial the phone.
    </string>
// main.xml
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
  <TextView xmlns:android="//schemas.android.com/apk/res/android"
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:autoLink="all"
            android:text="@string/link_text_auto"
            />


2.) Link text by setMovementMethod

// MainActivity.java onCreate
/*Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable(boolean) again after calling this to get the focusability back the way you want it. */

TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());

// main.xml
<!-- text2 uses a string resource containing explicit <a> tags to
       specify links. -->
  <TextView xmlns:android="//schemas.android.com/apk/res/android"
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/link_text_manual"
            />

//strings.xml

<string name="link_text_manual"><b>text2:</b> This is some other
      text, with a <a href="//www.google.com">link</a> specified
      via an <a> tag.  Use a \"tel:\" URL
      to <a href="tel:4155551212">dial a phone number</a>.
    </string>






3.) Link as html code using Html.fromHtml()

// MainActivity.java onCreate
        TextView t3 = (TextView) findViewById(R.id.text3);
        t3.setText(
            Html.fromHtml(
                "<b>text3:</b>  Text with a " +
                "<a href=\"//www.google.com\">link</a> " +
                "created in the Java source code using HTML."));
        t3.setMovementMethod(LinkMovementMethod.getInstance());




4.) Link string by SpannableString

        SpannableString ss = new SpannableString(
            "text4: Click here to dial the phone.");

        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        TextView t4 = (TextView) findViewById(R.id.text4);
        t4.setText(ss);
        t4.setMovementMethod(LinkMovementMethod.getInstance());


linkify link url adress text in Android
230

Eclipse "id cannot be resolved or is not a field” error Android | eclipse-id-cannot-be-resolved-or-is-not-a-field-error-android


"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:

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.


Editace Jana Žákovská : 2013-12-09 13:10:18
Počet článků v kategorii: 397
Url:create-bitmap-with-linear-gradient-android-example
Share
Share
Tweet