can't resolve drawable symbol - android

After i add an activity,‘NavigationVew’ in the previous activity display error that "can't resolve drawable symbol
package com.eight.zhan.kitchen;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.mancj.materialsearchbar.MaterialSearchBar;
public class Main2Activity extends AppCompatActivity
implements NavigationVew.OnNavigationItemSelectedListener
,MaterialSearchBar.OnSearchActionListener {
}
This is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.eight.zhan.kitchen"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}}dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.github.mancj:MaterialSearchBar:0.7'
compile 'com.android.support:support-v4:25.3.1'
}
The error message diaplay "package NavigationVew does not exist"
why?

i think need following two steps
Clean Project.
Rebuild Project.

NavigationVew mean nothing,it should be NavigationView.

Related

Can't import androidx.navigation.ui.AppBarConfiguration and androidx.navigation.ui.NavigationUI

I am trying to import androidx.navigation.ui.AppBarConfiguration and androidx.navigation.ui.NavigationUI into my main activity.
Here is my main activity:
package com.example.cyticketclient;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_sales,
R.id.navigation_messages,
R.id.navigation_forum,
R.id.navigation_profile).build();
}
}
I am getting the error
Cannot resolve symbol 'ui'
How do I get androidx.navigation.ui.AppBarConfiguration and androidx.navigation.ui.NavigationUI to import?
Here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.cyticketclient"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.navigation:navigation-runtime:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.android.volley:volley:1.1.1'
}
Classes in androidx.navigation.ui are in the navigation-ui dependency as per the Navigation declaring dependencies
implementation 'androidx.navigation:navigation-ui:2.3.0'

Kotlin-Android-Extension doesn't work across module?

I'm using Kotlint 1.3.50 and Android Studio 3.4
I have my code
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
my_txt.text = "ABC"
}
}
Any my layout as below
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/my_txt"
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"/>
</android.support.constraint.ConstraintLayout>
Everything compiles fine if they are in the same module.
However, if I move my layout to an android library, with gradle as below
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I can still import kotlinx.android.synthetic.main.activity_main.* and Android Studio doesn't complaint. But, when I compile, it complaints
Unresolved reference: activity_main
Unresolved reference: my_txt
Looks like the kotlin-extension can't cross use layout from another library?
If I change to findViewById<TextView>(R.id.my_txt).text = "XYZ", it works fine.
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<TextView>(R.id.my_txt).text = "XYZ"
}
}

Cannot resolve method 'setupWithViewPager(androidx.viewPager.widget.ViewPager)

I an learning android studio and was trying to make a simple app using fragments but I am getting the below error.
error- Cannot resolve method 'setupWithViewPager(androidx.viewPager.widget.ViewPager)'
My Code:
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.widget.TableLayout;
public class MainActivity extends AppCompatActivity {
private TableLayout tableLayout;
private ViewPager viewPager;
private ViewPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tableLayout= (TableLayout) findViewById(R.id.tab_layout);
viewPager=(ViewPager) findViewById(R.id.pager_id);
adapter=new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragement(new Fragment_call(),"Call");
adapter.AddFragement(new FragmentContact(),"Contact");
adapter.AddFragement(new FragmentFav(),"Favourite");
viewPager.setAdapter(adapter);
tableLayout.setupWithViewPager(viewPager);
}
}
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.ass"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//compile 'com.android.support:design:25.3.1'
}
Any help would be appreciated.
Didn't you mean TabLayout instead TableLayout?
If so, change tableLayout = (TableLayout) findViewById(R.id.tab_layout); to TabLayout tableLayout = findViewById(R.id.tab_layout);
tableLayout= (TableLayout) findViewById(R.id.tab_layout);
tableLayout.setupWithViewPager(viewPager);
The android.widget.TableLayout doesn't have the method setupWithViewPager.
Maybe you are looking for the com.google.android.material.tabs.TabLayout.
It requires the Material Components library as dependency:
implementation 'com.google.android.material:material:1.1.0'
It's TabLayout and not TableLayout. These are two different things.

A library is not working on Nougat (API Level 24)

I used compile 'com.sdsmdg.harjot:rotatingtext:1.0.2' in Android app. It is working in Android Marshmallow API 22 and lower versions. To be more precise, It rotates text with Animation. In Android with Api level 22 and lover it is showing text with Animation. But higher versions don`t support. What should I do to be supported in all versions of Android devices. Please Help.
Here is Source Code:
MainActivity.java
package com.example.abdusoli.rotatingtext;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.BounceInterpolator;
import android.widget.Button;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import com.sdsmdg.harjot.rotatingtext.RotatingTextWrapper;
import com.sdsmdg.harjot.rotatingtext.models.Rotatable;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Raleway-Light.ttf");
Typeface typeface2 = Typeface.createFromAsset(getAssets(), "fonts/Reckoner_Bold.ttf");
RotatingTextWrapper rotatingTextWrapper = (RotatingTextWrapper) findViewById(R.id.custom_switcher);
rotatingTextWrapper.setSize(35);
rotatingTextWrapper.setTypeface(typeface2);
Rotatable rotatable = new Rotatable(Color.parseColor("#FFA036"), 2000, " ", "Word01", "Word02");
rotatable.setSize(35);
rotatable.setAnimationDuration(600);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new BounceInterpolator());
rotatingTextWrapper.setContent("This is ?", rotatable);
}
}
gradle.build(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.abdusoli.rotatingtext"
minSdkVersion 16
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.+'
compile 'com.flaviofaria:kenburnsview:1.0.7'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.sdsmdg.harjot:rotatingtext:1.0.2'
}
Currently the library does not support higher versions
Issue has been raised on the repo in github

OnClick linstener using Butterknife not working

OnClick linstener using Butterknife is not working when i click button it's not happening any thing,someone please check the code below and suggest me any modifications if any.
MainActivity.java
package com.example.niranjan.sample;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
#BindView(R.id.button)
Button button;
#BindView(R.id.edit)
EditText edit;
#BindView(R.id.text)
TextView text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
#OnClick(R.id.button)
public void onClick(View view)
{
String text1 = edit.getText().toString();
text.setText(text1);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.niranjan.sample.MainActivity">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="addtext" />
</LinearLayout>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.niranjan.sample"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.jakewharton:butterknife:8.4.0'
testCompile 'junit:junit:4.12'
}
I done below steps and successfully implemented butter knife
In build.gradle(project)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply the 'android-apt' and dependency in build.gradle(app)
apply plugin: 'android-apt'
android {
...
}
dependencies {
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
I had the same problem, try this in your build.gradle(Module.app)
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
and then
apt 'com.jakewharton:butterknife-compiler:8.4.0'
also do not forget
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' in build.gradle(Project)
You neeed to add apt 'com.jakewharton:butterknife-compiler:8.4.0' under apply plugin in build.gradle
Also add
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
In your project build.gradle inside buildScript->dependencies

Categories

Resources