Application crashes on clicking options - android

So using Android Studio 2.3.1 I have the most simple app possible, using default settings and choosing a Basic App template. The app gets created just fine, but crashes if you try to click the options button at the top right corner - i.e. the three dots. This is a serious problem...
This is the error:
04-30 17:51:13.871 13942-13942/com.topository.optionstest01 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
04-30 17:51:17.987 13942-13942/com.topository.optionstest01 D/AndroidRuntime: Shutting down VM
04-30 17:51:17.988 13942-13942/com.topository.optionstest01 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.topository.optionstest01, PID: 13942
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at android.support.v7.view.menu.ListMenuItemView.setTitle(ListMenuItemView.java:127)
at android.support.v7.view.menu.ListMenuItemView.initialize(ListMenuItemView.java:113)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:100)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:803)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Here is my gradle.build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.topository.optionstest01"
minSdkVersion 23
targetSdkVersion 25
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:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
For completeness:
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my menu.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/settings"
android:orderInCategory="100"
android:title="Settings"
android:titleCondensed="The settings"
app:showAsAction="never"/>
</menu>
And the device is a Pixel running 7.1.2
Has anyone else come across this? Any ideas?

I have had the same issue, my app was crashing, and the example basic app from Android Studio was crashing on clicking "options"menu button (with three dots), too.
Crash log:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null
object reference
at
android.support.v7.view.menu.ListMenuItemView.setTitle(ListMenuItemView.java:127)
at
android.support.v7.view.menu.ListMenuItemView.initialize(ListMenuItemView.java:113)
at
android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:100)
at
android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at
android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
at
android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
at
android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
at
android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at
android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:803)
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)
Setup: Android Studio 2.3.1
Gradle 3.3
The solution that I have found was downgrading Gradle plugin from 3.3 down to 2.14.1
1) Replace the plugin version in
top-level build.gradle:
dependencies {
//REPLACED 2.3.3->2.2.3(MENU ISSUE)
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:2.2.3'
...
}
If you use a wrapper
2) delete the /gradle/wrapper/gradle-wrapper.jar
3) replace the contents of
/gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
build-> clean project -> rebuild project -> the crash when acessing three-dot upper-right corner menu had gone.

Related

Actionbar menu crashing on long-press

I have a menu item in the actionbar like below.
Menu code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.vroom, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_sos) {
sos_dialog();
return true;
}
return super.onOptionsItemSelected(item);
}
Menu 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_sos"
android:title="SOS"
android:icon="#drawable/fab_sos"
app:showAsAction="always" />
</menu>
Single click works as usual but if long-pressed it crashes with the following error:
java.lang.NoSuchFieldError: No field message of type I in class Landroid/support/v7/appcompat/R$id; or its superclasses (declaration of 'android.support.v7.appcompat.R$id' appears in /data/app/bd.com.vroom-1/base.apk:classes6.dex)
at android.support.v7.widget.TooltipPopup.<init>(TooltipPopup.java:60)
at android.support.v7.widget.TooltipCompatHandler.show(TooltipCompatHandler.java:154)
at android.support.v7.widget.TooltipCompatHandler.onLongClick(TooltipCompatHandler.java:103)
at android.view.View.performLongClickInternal(View.java:5714)
at android.view.View.performLongClick(View.java:5672)
at android.widget.TextView.performLongClick(TextView.java:9415)
at android.view.View.performLongClick(View.java:5690)
at android.view.View$CheckForLongPress.run(View.java:22398)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Though long-press works fine if icon is removed from menu xml. Any kind of suggestions to solve the crash will be highly appreciated.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "bd.com.vroom"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
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'
})
ext {
support_library_version = "26.1.0"
google_play_services_version = "11.0.1"
}
compile "com.android.support:appcompat-v7:${support_library_version}"
compile "com.android.support:mediarouter-v7:${support_library_version}"
compile "com.android.support:design:${support_library_version}"
compile "com.android.support:cardview-v7:${support_library_version}"
compile "com.android.support:recyclerview-v7:${support_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile "com.android.support:support-v13:${support_library_version}"
compile "com.google.android.gms:play-services-location:${google_play_services_version}"
compile "com.google.android.gms:play-services-maps:${google_play_services_version}"
compile "com.google.android.gms:play-services-places:${google_play_services_version}"
compile('com.github.worker8:tourguide:1.0.17-SNAPSHOT#aar') {
transitive = true
}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.afollestad.material-dialogs:core:0.9.4.4'
compile 'me.relex:circleindicator:1.2.2#aar'
compile 'com.patrickpissurno:ripple-effect:1.3.1'
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'jp.wasabeef:glide-transformations:2.0.2'
compile 'com.yuyakaido.android:card-stack-view:1.0.0-beta5'
compile 'noman.placesapi:placesAPI:1.1.3'
compile 'com.facebook.android:account-kit-sdk:4.+'
compile 'com.wdullaer:materialdatetimepicker:3.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
testCompile 'junit:junit:4.12'
}
Figured it out. Found this on the issue tracker https://issuetracker.google.com/issues/64594124
Basically if you have your own tooltip.xml file it will conflict with the new tooltip of the design library.
I had a NoSuchFieldError after updating to Android Support Library 26.1.0 with the stacktrace posted below. But renaming my own tooltip.xml solved the issue as well.

Custom SearchView crash on Release build

I'm getting a crash when trying to get a reference to a Custom SearchView class in onCreateOptionsMenu. Normally this works fine but when loading the release apk, it crashes. I tried adding these lines to my proguard but its still crashing:
# Android support
-keep public class com.mine.mobile.mypackage.usercontrol.SearchViewCustom
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
Here is the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
mMenu = menu;
getMenuInflater().inflate(R.menu.menu_invest, menu);
final MenuItem searchItem = menu.findItem(R.id.action_invest_search);
if (searchItem != null) {
mSearchView = (SearchViewCustom) MenuItemCompat.getActionView(searchItem);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}
mPresenter = new BaseActivityPresenterImpl(this,mSearchView,mMenu,searchItem);
mPresenter.setupActionBar(NONE,false);
return super.onCreateOptionsMenu(menu);
}
Here is the log
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mine.mobile.mypackage.usercontrol.d.setSearchableInfo(android.app.SearchableInfo)' on a null object reference
! 1 at com.mine.mobile.mypackage.activity.home.a.onCreateOptionsMenu(BaseActivity.java:94)
2 at android.app.Activity.onCreatePanelMenu(Activity.java:3232)
3 at android.support.v4.app.q.onCreatePanelMenu(FragmentActivity.java:362)
4 at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:98)
5 at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:335)
6 at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:98)
7 at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:454)
8 at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
9 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
10 at android.view.Choreographer.doCallbacks(Choreographer.java:683)
11 at android.view.Choreographer.doFrame(Choreographer.java:616)
12 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
13 at android.os.Handler.handleCallback(Handler.java:751)
14 at android.os.Handler.dispatchMessage(Handler.java:95)
15 at android.os.Looper.loop(Looper.java:154)
16 at android.app.ActivityThread.main(ActivityThread.java:6247)
17 at java.lang.reflect.Method.invoke(Native Method)
18 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
19 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
menu.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_delete"
android:title="#string/delete"
android:icon="#drawable/ic_delete_white"
app:showAsAction="always" />
<item
android:id="#+id/action_done"
android:title="#string/done"
android:icon="#drawable/ic_done_white"
app:showAsAction="always" />
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_refresh_white"
android:visible="false"
android:title="#string/refresh_menu"
app:showAsAction="always" />
<item
android:id="#+id/action_invest_search"
android:icon="#drawable/ic_search_white"
android:visible="false"
android:title="#string/action_search"
app:actionViewClass="com.mine.mobile.mypackage.usercontrol.SearchViewCustom"
app:showAsAction="always|collapseActionView" />
</menu>
This is not a duplicate of What is a NullPointerException, and how do I fix it? ...that question encompasses way too broad a category
I was on the right track but apparently my pro guard syntax was incorrect (I used google's example here:). This worked though:
-keep public class com.mine.mobile.mypackage.usercontrol.SearchViewCustom {
public *;
}

Android overflow menu nullPointerException when clicking three dots

The normal button works fine, but clicking the three dots button makes an exception
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
my xml file
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:icon="#drawable/refresh"
android:id="#+id/action_main_refresh"
app:showAsAction="always"
android:title="#string/refresh" />
<item
android:id="#+id/action_main_search"
android:title="#string/search"
android:icon="#drawable/seach"
app:showAsAction="always"/>
<item
android:id="#+id/action_main_top"
android:title="#string/sort_top"
app:showAsAction="never" />
</menu>
Logs
06-22 23:12:49.481 1289-1289/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at android.support.v7.view.menu.ListMenuItemView.setTitle(ListMenuItemView.java:127)
at android.support.v7.view.menu.ListMenuItemView.initialize(ListMenuItemView.java:113)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:100)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:803)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
click listener
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//Log.i(TAG, "sort URL: " + makeUrlCustom(item.getItemId()));
switch(item.getItemId()){
case R.id.action_main_refresh:
if(!adapter.isEmpty()) adapter.clear();
noData.setVisibility(View.GONE);
get(url, null);
return true;
case R.id.action_main_search:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText dialogText = new EditText(this);
alert.setView(dialogText);
alert.setTitle("Search subreddit");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
url = dialogText.getText().toString();
if(!adapter.isEmpty()) adapter.clear();
noData.setVisibility(View.GONE);
Log.i(TAG, "url from searchText is: " + url);
if(url.equals("") || url == null){
Toast.makeText(MainActivity.this, "Please insert valid subreddit", Toast.LENGTH_SHORT).show();
}else{
get(url, null);
}
}
});
// create alert dialog
AlertDialog alertDialog = alert.create();
// show it
alertDialog.show();
return true;
case R.id.action_main_top:
Log.i(TAG, "sort top");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
clicking on the menu overflow causes npe (in this case, the action_main_top).
clicking on the normal menu (refresh & search) works fine.
after doing an exhaustive research, I found this answer here: App Crashes on Clicking Options
That answer solved my issue, aparently the issue is only for the Gradle version 2.3.3 and you need to downgrade to the 2.2.3 in order to fix it. (Hope that soon fix this bug to upgrade)
Here I paste the solution provided by Alex Bouroff
The solution that I have found was downgrading Gradle plugin from 3.3 down to 2.14.1
1) Replace the plugin version in top-level build.gradle:
dependencies {
//REPLACED 2.3.3->2.2.3(MENU ISSUE)
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:2.2.3'
...
}
If you use a wrapper 2) delete the /gradle/wrapper/gradle-wrapper.jar
3) replace the contents of /gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
build-> clean project -> rebuild project -> the crash when acessing three-dot upper-right corner menu had gone.

Action Share Button works on debug mode but does not work on release mode

main_activity.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_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/menu_item_share"
app:showAsAction="ifRoom"
android:title="#string/action_share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
</menu>
MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
// Get its ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
// Connect the dots: give the ShareActionProvider its Share Intent
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(mShareIntent());
}
return true;
}
private Intent mShareIntent() {
Intent mShareIntent = new Intent();
mShareIntent.setAction(Intent.ACTION_SEND);
mShareIntent.setType("text/plain");
mShareIntent.putExtra(Intent.EXTRA_TEXT,"https://play.google.com/store/apps/details?id=com.android.qwe");
return mShareIntent;
}
ToolBar code in Fragment
Toolbar toolbar = (Toolbar) v.findViewById(R.id.toolbar);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
Gradle file
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.zapz.android.quizy"
minSdkVersion 9
targetSdkVersion 23
versionCode 4
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.0'
SHARE BUTTON appears as text[SHARE] in release mode but in debug mode its working fine with share icon appearing on the toolbar.
Im using a toolbar and not action bar

Issues while running App developed using Android Material Design

I have been working on an app using material design. I am completely new to this. I have been looking this tutorial for reference material design . But I am not getting "settings" option displayed in the top right corner of the toolbar. The toolbar is getting displayed but not the "3 dots settings" button . I am following the same as per the tutorial but I don't know why the settings is not getting displayed.
Here is my styles.xml code:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
</style>
</resources>
and my styles.xml(v-21) code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
</style>
My build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "app.xxx.yyy.myapplication"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.+'
}
I have attached the image of the result I am getting. Please help me get through it!
I don't think the problem comes from material stuff but the toolbar or option menus. You should share your mainActivity code if possible.
check ur code with it...
menu.xml
<menu 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"
tools:context="com.example.toolbar.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
</menu>
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
// toolbar.setNavigationIcon(R.drawable.back);
toolbar.setLogo(R.drawable.ic_launcher);
//toolbar.setTitle("Title");
// toolbar.setSubtitle("Subtitle");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<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"
tools:context="com.example.toolbar.MainActivity" >
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_awesome_toolbar"
android:layout_width="fill_parent"
android:layout_height="128dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ActionBarThemeOverlay">
</android.support.v7.widget.Toolbar>
</RelativeLayout>

Categories

Resources