i'm making my first app.
it is a simple application with a splash screen and the main activity and now with flavours i have two build variants:
Free Version: With Admob banner on bottom of the activity
Paid Version: The app don't show admob banner on the bottom but replace it with a Bottom Navigation View for switch activity ( i will add another activity for this).
I tell you that before i add this Bottom Navigation View all part of application work properly, include Build variants.
This is what i did for add Botttom Navigation Menu:
First i put the Bottom Navigation View on the bottom of the xml activity file:
valutausato.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="8dp"
android:layout_centerHorizontal="true">
<TextView
android:id="#+id/TitoloText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="VALUTA IL TUO USATO"
android:textSize="32dp"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:fontFamily="sans-serif-condensed"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="70dp"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Prezzo In Negozio:"
android:fontFamily="sans-serif"
android:textStyle="bold|italic"
android:textColor="#111"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_centerHorizontal="true">
<EditText
android:id="#+id/ProdottoNuovoTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="2dp"
android:layout_weight="1"
android:inputType="numberDecimal"
android:digits="0123456789."
android:maxLength="30"
android:text="Inserisci qui il prezzo.."
android:textSize="22dp"
android:fontFamily="sans-serif-condensed"
android:textColor="#color/colorPrimary"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Garanzia"
android:layout_marginRight="0dp"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Condizioni prodotto"
android:fontFamily="sans-serif"
android:textColor="#111"
android:textStyle="bold|italic"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="250dp"
android:layout_centerHorizontal="true"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<Spinner
android:id="#+id/ProdottoDanneggiatospn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="0dp"
android:textColor="#color/colorPrimary"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accessori"
android:layout_weight="1"
android:fontFamily="sans-serif"
android:textStyle="bold|italic"
android:textColor="#111"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="340dp"
android:layout_centerHorizontal="true"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/PartiMancantispn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="0dp"
android:textColor="#color/colorPrimary"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="400dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/BtnCalcola"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calcola"
android:background="#color/ColorButton"
android:layout_weight="1"
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold|italic"
android:textSize="17dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="470dp"
android:layout_weight="1">
<TextView
android:id="#+id/FormPrezzoFinale"
android:textSize="22dp"
android:fontFamily="sans-serif-condensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#002F80"
android:layout_weight="1"
android:text="prova"/>
</LinearLayout>
<android.support.design.internal.BottomNavigationView
android:id="#+id/MenuBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#drawable/background_menu_color"
app:itemTextColor="#drawable/background_menu_color"
app:menu="#menu/background_menu_main"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/SmartBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="60dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
After this i setup my app.build.gradle file with correct dependencies
app.build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.viniusapp.value"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
freeVersion {
dimension "version"
applicationId "com.viniusapp.value.lite"
versionName = "1.0-lite"
}
paidVersion {
dimension "version"
applicationId "com.viniusapp.value.premium"
versionName = "1.0-premium"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.android.support:design:26.1.0'
}
Later i create in the drawable folder the file for the bottom navigation view
background_menu_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorPrimaryDark" android:state_enabled="true"/>
<item android:color="#color/colorPrimary" android:state_enabled="true"/>
</selector>
And finally i create "menu"folder in the main res folder and create the xml file for menu item and create two image assets for this two actions.
background_menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/Action_Value"
android:enabled="true"
android:icon="#drawable/ic_value"
android:title="Valuta"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/Action_Search"
android:enabled="true"
android:icon="#drawable/ic_search"
android:title="Cerca Sul Web"
app:showAsAction="ifRoom"
/>
</menu>
The last thing i did is add BottomNavigation view in java file (I remove all the rest of the code that was useless for this problem)
package com.vkapp.valutatoreusato;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.internal.BottomNavigationMenuView;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import junit.runner.Version;
import java.lang.reflect.Type;
public class ValutaUsato extends Activity {
int Iva = 22;
double PriceProductNew;
double SalePriceOfProduct = 0;
boolean FirstLaunch = true;
int NumeroUtilizziTotali = 0;
Button BtnCalcola = null;
EditText PriceProductNewTxt = null;
TextView SalePriceText = null;
Spinner DamageProductState = null;
Spinner MissPartProductState = null;
InterstitialAd mInterstitialAd;
AdView SmartBanner;
BottomNavigationMenuView BottomNavigationMenuMoveForMove = null;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
BtnCalcola = (Button) findViewById(R.id.BtnCalcola);
BtnCalcola.setEnabled(false);
PriceProductNewTxt = (EditText) findViewById(R.id.ProdottoNuovoTxt);
SalePriceText = (TextView) findViewById(R.id.FormPrezzoFinale);
DamageProductState = (Spinner) findViewById(R.id.ProdottoDanneggiatospn);
MissPartProductState = (Spinner) findViewById(R.id.PartiMancantispn);
BottomNavigationMenuMoveForMove = (BottomNavigationMenuView) findViewById(R.id.MenuBottom);
BottomNavigationMenuMoveForMove.setEnabled(false);
super.onCreate(savedInstanceState);
setContentView(R.layout.valutausato);
if (BuildConfig.FLAVOR.equals("freeVersion")) {
Log.d("TAG", "Free Version running");
Log.d("TAG", BuildConfig.APPLICATION_ID);
Log.d("TAG", BuildConfig.VERSION_NAME);
MobileAds.initialize(this, "ca-app-pub-3526806334939799/1381568933");
SmartBanner = findViewById(R.id.SmartBanner);
AdRequest adRequest = new AdRequest.Builder().build();
SmartBanner.loadAd(adRequest);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
;
}
if (BuildConfig.FLAVOR.equals("paidVersion")) {
Log.d("TAG", "Paid Version running");
BottomNavigationMenuMoveForMove.setEnabled(true);
Log.d("TAG", BuildConfig.APPLICATION_ID);
Log.d("TAG", BuildConfig.VERSION_NAME);
}
}
}
After that my project look like this:
Project Structure
Preview of main activity
But now when i deubg/run the app the splash screen work good but when the main activity start the app crash with this errors:
01-11 18:07:54.000 7279-7279/com.viniusapp.value.lite E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.viniusapp.value.lite, PID: 7279
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.viniusapp.value.lite/com.vkapp.valutatoreusato.ValutaUsato}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.BottomNavigationView" on path: DexPathList[[zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/base.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419)
at android.app.Activity.setContentView(Activity.java:2669)
at com.vkapp.valutatoreusato.ValutaUsato.onCreate(ValutaUsato.java:66)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
I see that this error
at com.vkapp.valutatoreusato.ValutaUsato.onCreate(ValutaUsato.java:66)
link me this statement
BottomNavigationMenuMoveForMove = (BottomNavigationMenuView) findViewById(R.id.MenuBottom);
I hope this is all clear for you.
Thanks for any help
You are using wrong class in your xml code. It should be:
<android.support.design.widget.BottomNavigationView
instead of
<android.support.design.internal.BottomNavigationView
Difference is in keywords: internal and widget.
Next inside your Activity change BottomNavigationMenuView to BottomNavigationView. Also make sure that
super.onCreate(savedInstanceState);
setContentView(R.layout.valutausato)
code is on top of onCreate not after connecting with IDs.
Copy all drawables from "drawable-v21" folder to "drawable".
You are using the wrong class. You have BottomNavigationMenuView object in the code but your actual view is BottomNavigationView.
Change your code to this instead:
BottomNavigationView bottomNavView = (BottomNavigationView) findViewById(R.id.MenuBottom);
add the following lines in proguard-rules.pro file:
-dontwarn org.xmlpull.v1.XmlPullParser
-dontwarn org.xmlpull.v1.XmlSerializer
-keep class org.xmlpull.v1.* {*;}
Related
I'm using the following library: https://github.com/deano2390/MaterialShowcaseView
I've been trying to find a way (for 2 days straight!) to always position the "GOT IT" button on the bottom left corner of the screen. How do I achieve that simply and effectively?
I will immediately accept the working answer. As you can see, I have a history of always accepting answers.
With Osama's answer, I get error:
com.example.me.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.me.myapplication, PID: 4445
java.lang.IllegalStateException: Cannot start this animator on a detached view!
at android.view.RenderNode.addAnimator(RenderNode.java:812)
at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:300)
at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:282)
at android.animation.RevealAnimator.<init>(RevealAnimator.java:37)
at android.view.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:55)
at uk.co.deanwild.materialshowcaseview.CircularRevealAnimationFactory.animateInView(CircularRevealAnimationFactory.java:29)
at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView.animateIn(MaterialShowcaseView.java:825)
at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView$1.run(MaterialShowcaseView.java:794)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
MainActivity:
package com.example.me.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// single example
new MaterialShowcaseView.Builder(this)
.setTarget(findViewById(R.id.hi))
.setDismissText("GOT IT")
.setContentText("This is some amazing feature you should know about! Indeed, this is just an example of a bug that can be easily fixed!")
.show();
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.me.myapplication.MainActivity">
<TextView
android:id="#+id/hi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.419" />
</android.support.constraint.ConstraintLayout>
This lib is based on ShowcaseView, take a look at it.
You can also go to the showcase_content.xml at the library module and put the tv_dismiss that is the "GOT IT" TextView into a RelativeLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_box"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:weightSum="1">
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="30dp" />
<TextView
android:id="#+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tv_dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:textColor="#android:color/white"
android:textSize="22dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
Go to MaterialShowcaseView.java and empty the applyLayoutParams() method and update the setDelay to 1000
Within the builder, add the following code.
mDismissButton.setGravity(Gravity.BOTTOM);
I have two v4 Fragments in one v7 AppCompatActivity. One fragmet has AppCompatImageButton, the other AppCompatButton. The first one inflates just fine, the other fails with a cryptic error
android.view.InflateException: Binary XML file line #70: Binary XML file line #70: Error inflating class android.support.v7.widget.AppCompatButton
caused by java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue. Both fragments are inflated from the same activity and use the same theme. The only difference is that one button is AppCompatImageButton with just an icon, the other AppCompatButton with an icon and text.
The XML file line #70 is the line where AppCompatButton is defined.
I guess the problem is due to a missing attribute in the Theme, the one at index 5, but how do I find what's at index 5? I tried adding/removing android:tint and android:background, it made no difference.
Here is the relevant piece of the trace:
android.view.InflateException: Binary XML file line #70: Binary XML file line #70: Error inflating class android.support.v7.widget.AppCompatButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at co.tinode.tindroid.TopicInfoFragment.onCreateView(TopicInfoFragment.java:42)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
Caused by:
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x1010433 a=2 r=0x7f0d0029}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:482)
at android.widget.TextView.<init>(TextView.java:1043)
at android.widget.Button.<init>(Button.java:109)
at android.widget.Button.<init>(Button.java:105)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at co.tinode.tindroid.TopicInfoFragment.onCreateView(TopicInfoFragment.java:43)
The code at TopicInfoFragment.java:43 is just
return inflater.inflate(R.layout.fragment_topic_info, container, false);
Here is the layout for the Fragment that fails (button on the bottom):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:padding="#dimen/activity_padding"
android:orientation="vertical"
tools:context="co.tinode.tindroid.TopicInfoFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imageAvatar"
android:layout_width="#dimen/avatar_size_large"
android:layout_height="#dimen/avatar_size_large"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="8sp"
android:layout_marginStart="8sp"
android:clickable="true"
android:contentDescription="#string/avatar"
android:src="#drawable/ic_group"/>
<TextView
android:id="#+id/topicTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dialog_item_padding"
android:layout_toLeftOf="#id/imageAvatar"
android:layout_toStartOf="#id/imageAvatar"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="true"/>
<TextView
android:id="#+id/topicSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/topicTitle"
android:layout_marginTop="#dimen/dialog_item_padding"
android:ellipsize="end"
android:maxLines="1"
android:textIsSelectable="true"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#66000000"/>
<TextView
android:id="#+id/membersTitle"
style="#style/sectionTitleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dialog_item_padding"
android:text="#string/group_members"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- THIS BUTTON FAILS TO INFLATE -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonAddMember"
android:contentDescription="#string/add_member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_person_add"
android:drawableStart="#drawable/ic_person_add"
android:text="#string/add_member"
android:drawablePadding="4sp"
android:textColor="#color/colorText"
android:background="?attr/selectableItemBackgroundBorderless"
/>
</LinearLayout>
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollAlwaysVisible="true"
android:scrollbarStyle="outsideInset"
android:verticalScrollbarPosition="right"/>
</LinearLayout>
Here is the the layout which inflates just fine in the same activity:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/message_view_bkg"
tools:context="co.tinode.tindroid.MessagesFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/messages_container"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/sendMessagePanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:stackFromEnd="true"
app:reverseLayout="false"/>
<LinearLayout
android:id="#+id/sendMessagePanel"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingLeft="6sp"
android:paddingStart="6sp"
android:orientation="horizontal"
android:background="#android:color/background_light">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editMessage"
android:inputType="text"
android:hint="#string/new_message_hint"
android:imeOptions="actionSend"
android:layout_weight="1" />
<!-- This button inflates just fine -->
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/chatSendButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_send"
android:contentDescription="#string/send_message_button_hint"
android:tint="#android:color/holo_blue_dark"
android:layout_weight="0.1"
android:paddingLeft="4sp"
android:paddingRight="8sp"
android:background="?attr/selectableItemBackgroundBorderless" />
</LinearLayout>
</RelativeLayout>
The theme is quite basic:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
</style>
Here is the gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "co.tinode.tindroid"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(path: ':tinodesdk')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:preference-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.googlecode.libphonenumber:libphonenumber:8.4.0'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
OK, solved. The problem was with the android:textColor="#color/colorText".
colorText was defined as a reference <color name="colorText">?android:attr/colorPrimary</color>. Once I defined it explicitly, the problem went away.
I'm trying to implement an Android spinner in my app but am running into some problems with the java file associated with the Activity its placed in.
The errors I am getting are as follows:
1. setContentView(R.layout.activity_display_asleep_at);
- cannot be resolved or is not a field
2. cycles_array (where ArrayAdapter<CharSequence> is...)
- cannot be resolved or is not a field
3. spinner (where "android.widget.Spinner spinner" is...)
- cannot be resolved or is not a field
The code I have is as follows:
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.Spinner;
public class DisplayAsleepAt extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_asleep_at);
getActionBar().setDisplayHomeAsUpEnabled(true);
android.widget.Spinner spinner = (android.widget.Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.cycles_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
Here is the xml file I am using:
<Spinner
android:id="#+id/AA_spinner_prompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/AA_spinner_promptTXT"
android:layout_alignParentRight="true" />
And here is the strings.xml file I have the array in:
<string-array name="cycles_array">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
</string-array>
If anyone has any ideas as to what might have gone wrong, it would be greatly appreciated. I can always post more if you need. Thanks all.
EDIT:
Here is the entire xml file I am using. I've been looking through it for a while and can't seem to find anything wrong with it...maybe I'm just tired at this point...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp" >
<TextView
android:id="#+id/AA_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/AA_titleTXT"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:textSize="35dp"
android:textStyle="italic"
tools:context=".DisplayAsleepAt" />
<TextView
android:id="#+id/AA_intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/AA_introTXT"
android:textSize="15dp"
android:layout_below="#id/AA_title" />
<Button
android:id="#+id/AA_button_pick"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/AA_button_pickTXT"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:onClick="showTimePickerFragment" />
<TextView
android:id="#+id/AA_rem_cycles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/AA_rem_cyclesTXT"
android:textSize="15dp"
android:layout_marginBottom="20dp"
android:layout_below="#id/AA_button_pick" />
<Spinner
android:id="#+id/AA_spinner_prompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/AA_spinner_promptTXT" />
<TextView
android:id="#+id/AA_final_time"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="#string/AA_final_timeTXT"
android:textSize="15dp" />
<Button
android:id="#+id/AA_create_alarm_button"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/AA_create_alarm_buttonTXT"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The error means there's something syntactically wrong with your XML layouts and R cannot be auto-generated. Try looking at your xml code and if you still have problem then post your xml code.
Change this code
android.widget.Spinner spinner = (android.widget.Spinner) findViewById(R.id.spinner);
To
android.widget.Spinner spinner = (android.widget.Spinner) findViewById(R.id.AA_spinner_prompt);
Hope it helps
Remove this line from your code :
import android.R;
and then Clean & Rebuild your project.
I am new to Android/java programming. I really have no clue what I am doing, and would like a little help. What I am trying to do is build a form very similar to the one below. I have already put in all of the layout, and strings information, but I am having trouble with the functions. The error that I am getting is View cannot be resolved to a type line 14. I am using eclipse to help me program this app. Here is my main.xml, and MadisonStudios.java file's contents as well.
http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-forms/
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/welcome" />
<EditText
android:id="#+id/EditTextName"
android:layout_height="wrap_content"
android:hint="#string/name"
android:inputType="textPersonName"
android:layout_width="fill_parent">
</EditText>
<EditText
android:id="#+id/EditTextEmail"
android:layout_height="wrap_content"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:layout_width="fill_parent">
</EditText>
<Spinner
android:id="#+id/SpinnerStatus"
android:layout_height="wrap_content"
android:prompt="#string/status"
android:layout_width="fill_parent"
android:entries="#array/statuslist">
</Spinner>
<EditText
android:id="#+id/EditTextFeedbackBody"
android:layout_height="wrap_content"
android:hint="#string/changebody"
android:inputType="textMultiLine"
android:lines="5"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/ButtonSendChange"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="sendChange"
android:text="#string/changebutton">
</Button>
</LinearLayout>
MadisonStudios.java
package com.madisonstudios.supportapp;
import android.app.Activity;
import android.os.Bundle;
public class MadisonStudios extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void sendChange(View button) {
// Do click handling here
}
}
import android.view.View;
Add this line in import statements..
You should import it. If you are using Eclipse, press Ctrl+Shift+o.
I am attempting to use the layout tricks #3 described in Android Layout Tricks #3: Optimize, Part 1 and I am getting an error when its trying to find the png file that I am using as the button obj my XML file for the button bar is the following .....
<?xml version="1.0" encoding="UTF-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<include
layout = "#drawable/button_yes"
android:id="#+id/okLabel" />
<include
layout="#drawable/button_no"
android:id="#+id/cancelLabel" />
</merge>
and this is called by the java script......
package com.bobocode.culliganapp;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
public class OkCancelBar extends FrameLayout {
public OkCancelBar(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.okcancelbar, this, true);
}
}
which is being instantiated by ..............
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:okCancelBar="http://schemas.android.com/apk/res/com.bobocode.culliganapp">
<FrameLayout android:background="#drawable/culliganapp1"
android:id="#+id/secondpage"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dip"
android:layout_gravity="center|center"
android:padding="12dip"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center|center"
android:padding="12dip"
android:background="#color/white"
android:textSize="24sp"
android:textColor="#color/black"
android:text="Does your water have an unpleasant taste or odor?"
android:id="#+id/question"
/>
</FrameLayout>
<com.bobocode.culliganapp.OkCancelBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:paddingTop="8dip"
android:gravity="center_horizontal"
android:background="#AA000000"
okCancelBar:okLabel="Yes"
okCancelBar:cancelLabel="No"
/>
</merge>
any help would surely be appreciated
If you want to specify a drawable for your background you'll need to include the png in your drawable directory and specify it on your OkCancelBar with android:background="drawable/somepng".
Use normal character like "yesbutton" . And i don't know why you want to do :
Layout ="#drawable/button_yes"
just do something like android:background="#drawable/yesbutton"
i don't know what
layout is, is not even android because all attributs starts with "android:".