Mostrando entradas con la etiqueta android studio. Mostrar todas las entradas
Mostrando entradas con la etiqueta android studio. Mostrar todas las entradas

Error: android.content.res.Resources$NotFoundException

Ocurre porque algun estilo o elemento no existe o no corresponde con la version de Android seleccionada para hacer el rendering.

Por ejemplo, en este caso la linea en rojo es la que produce el error:

<TextView    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:textAppearance="@color/abc_primary_text_material_dark"
    android:text="[puntaje]"    android:id="@+id/text1"    android:layout_alignParentTop="true"    android:layout_alignParentLeft="true"    android:layout_alignParentStart="true"    android:textAlignment="center"    android:textStyle="bold"    android:typeface="monospace" />

Quitando esta linea se soluciona el problema.

Cambiar la imagen de un ImageView

private Bitmap bm1, bm2;

amarilloOff.setImageResource(R.drawable.amarillo_off);
bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.amarillo_on);
bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.amarillo_off);

amarilloOff.setImageBitmap(bm1);

Configurar Admob con Google Play Services en Android

1. Agregar en build.gradle la linea 'com.google.android.gms...'

apply plugin: 'android'
...

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:5.0.77'
}

IR A TOOLS / ANDROID / SYNC PROJECT WITH GRADLE FILES y esperar a que las referencias queden bien (no queden en rojo)

2. Agregar un import en el .java

import com.google.android.gms.ads.*;

3. Agregar en AndroidManifest.xml (dentro del tag <application>)

        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

4. Antes del tag <application> agregar:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

5. Usar este codigo en el MyActivity.java

package com.expressraider.admob;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.android.gms.ads.*;

public class MyActivity extends Activity {

    private AdView mAdView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_principal);

        //------------- ADS --------------------------//
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);

        // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
        mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.SMART_BANNER);
        mAdView.setAdUnitId("ca-app-pub-0665940275249022/9155234413");

        mAdView.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));

        TelephonyManager teleManager =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
        String device_id=teleManager.getDeviceId();

        //obtengo el id del telefono, para agregarlo como dispositivo de testing
        String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        String deviceId = md5(android_id).toUpperCase();

        AdRequest adRequest=new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice(deviceId).build();

        FrameLayout.LayoutParams initialFrm = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        this.addContentView(mAdView, initialFrm);

        mAdView.loadAd(adRequest);
    }

    @Override
    public void onResume() {
        super.onResume();

        // Resume the AdView.
        mAdView.resume();
    }

    @Override
    public void onPause() {
        // Pause the AdView.
        mAdView.pause();

        super.onPause();
    }

    @Override
    public void onDestroy() {
        // Destroy the AdView.
        mAdView.destroy();

        super.onDestroy();
    }
}



6. Si da error cuando se ejecuta, ver en el LogCat esta linea:


7. En mAdView.setAdUnitId hay que poner el pub ID, que se obtiene de admob de esta forma:

ir a admob
ir a ficha Monetizar
ver en los bloques de anuncios, que dice ca-app-pub-0665940275249022/9155234413
ese es el que hay que poner.





ca-app-pub-0665940275249022/9155234413

Cannot resolve symbol Activity

Si aparecen errores de "Cannot resolve symbol..."

Verificar en app/build.gradle que las versiones se correspondan

por ej.

MAL:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.expressraider.prueba1"
        minSdkVersion 11
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}


BIEN

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.expressraider.prueba1"
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}

Mantener seleccionado un item del ListView

public class MantMatriculas extends Activity {
    private ListView lstMatriculas;
    private View lastSelectedView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mant_matriculas);

        lstMatriculas = (ListView)findViewById(R.id.lstMatriculas);

        ArrayList<String> values =
                new ArrayList<String>();

        values.add("matricula1");
        values.add("matricula2");
        values.add("matricula3");
        values.add("matricula4");

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

        lstMatriculas.setAdapter(adapter);


        lstMatriculas.setItemsCanFocus(false);
        lstMatriculas.setChoiceMode(ListView.CHOICE_MODE_SINGLE);


        lstMatriculas.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
                                    long id) {
               
                if (lastSelectedView != null)
                {
                    lastSelectedView.setBackgroundColor(Color.TRANSPARENT);
                }
                lastSelectedView = view;

                view.setBackgroundColor(Color.CYAN);
            }
        });
    }
}

Centrar texto en TextView

1. Agregar un linear layout (horizontal)
2. Agregar un TextView dentro del linear layout
3. Setear la propiedad gravity del linear layout en Center (la gravity no la layout:gravity)

Table layouts en Android Studio y anchos con porcentaje

1. Insertar un LinearLayout (horizontal)
2. Agregar dos botones
3. A un boton, ponerle layout:width: 0 y layout:weight: .80
4. Al otro ponerle layout:width: 0 y layout:weight: .20

Cambiar el estilo de la aplicacion en Android Studio

Editar el archivo \src\main\res\values\styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Light">
        <!-- Customize your theme here. -->
    </style>
</resources>

Barcode scanner con ZBarScanner en Android Studio

[El codigo fuente esta en Google Drive, en la carpeta Android Studio]

https://github.com/dm77/ZBarScanner

Ejemplo de lista clickeable con Android Studio

package com.example.crusso_pc.app1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        ListView lv = (ListView) findViewById(R.id.lista1);
        String[] values = new String[] { "Android List View",
                "Adapter implementation",
                "Simple List View In Android",
                "Create List View Android",
                "Android Example",
                "List View Source Code",
                "List View Array Adapter",
                "Android Example List View"
        };

        /* Tambien se puede hacer con arrraylists!
 
           ArrayList<String> values =
                new ArrayList<String>();

           values.add(matricula);
           values.add("matricula1");
           values.add("matricula2");
           values.add("matricula3");
           values.add("matricula4");
        */

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

        lv.setAdapter(adapter);
     
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
                                    long id) {

                // We know the View is a TextView so we can cast it
                TextView clickedView = (TextView) view;

                Toast.makeText(MyActivity.this, "Item with id [" + id + "] - Position [" + position + "] - Planet [" + clickedView.getText() + "]", Toast.LENGTH_SHORT).show();

            }
        });
    }
}

Android Studio 0.8.1 - step by step

1. Ir al SDK manager, ejecutando c:\android-studio\sdk\tools\android.bat (invocar el SDK manager asi
evita el error "sdk manager a folder failed to be moved")

2. Instalar Android 4.1.2 (api 16) y las android sdk tools, sdk platform-tools y sdk build-tools

3. Crear un nuevo AVD (Android virtual device) con estos settings

Device: Nexus 4
Target: Android 4.1.2 - API Level 16
CPU/ABI: ARM (armeabi-v7a)
Skin: Skin with dynamic hardware controls

5. Abrir el android studio, crear un nuevo proyecto con la version de SDK 16.

6. El apk lo genera automaticamente en esta ruta 
C:\Users\CRUSSO_PC\AndroidStudioProjects\App1\app\build\outputs\apk\app-debug.apk
(se puede pasar al cel e instalarla)

(Si un componente (ej, calendarView) no se puede usar por un problema con la version de SDK:
       Ir al archivo AndroidManifest.xml (en la raiz del proyecto), y hacer click en "uses sdk", 
       y cambiar la "min sdk version" a 11 por ej.

Leer codigos de barra con zxing y android studio


http://expocodetech.com/lectura-de-codigo-de-barras-en-android/

http://wahidgazzah.olympe.in/integrating-zxing-in-your-android-app-as-standalone-scanner/

Android Studio y GameMaker

ANDROID STUDIO
Ejemplo 1 - Click en boton


http://www.youtube.com/watch?v=RCyuqMVGl4g

GAMEMAKER

http://www.youtube.com/watch?v=v5dpj6Ms608

TRABAJAR CON PARTICLES !!! LEER !!
help.yoyogames.com/entries/27032963-Quick-Start-To-Programming-Particles