I am facing one of the most bizarre issues in rcent times. I am using AppCompatActivity with android support v7. When I am running the app in debug mode I can see the menus with icons, after generating signed apk and installing, the icons vanishes from menu.
Here is my menu code
<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=".TerminalActivity">
<item android:id="@+id/action_streamConnect"
app:showAsAction="never"
android:icon="@mipmap/ic_stream"
android:visible="false"
android:title="Connect to Stream">
</item>
<item android:id="@+id/action_connect"
app:showAsAction="never"
android:icon="@mipmap/ic_bluetooth_connect"
android:visible="true"
android:title="@string/action_connect">
</item>
<item android:id="@+id/action_disconnect"
android:title="@string/action_disconnect"
android:icon="@mipmap/ic_bluetooth_disconnect"
android:visible="false"
app:showAsAction="never" />
<item android:id="@+id/action_pulse"
android:title="Start Pulse"
android:icon="@mipmap/finger"
android:visible="true"
app:showAsAction="never" />
<item android:id="@+id/action_resp"
android:title="Respiration"
android:checkable="true"
android:checked="false"
android:visible="true"
android:icon="@mipmap/ic_lungs"
app:showAsAction="never" />
<item android:id="@+id/action_activity"
android:title="Track Activity"
android:checkable="true"
android:checked="false"
android:visible="true"
android:icon="@mipmap/icon_activity_track"
app:showAsAction="never" />
<item android:id="@+id/action_myRecords"
android:title="My Records"
android:visible="true"
android:icon="@mipmap/ic_download"
app:showAsAction="never" />
<item android:id="@+id/action_customUrlAnalyze"
android:title="Analyze Record"
android:visible="true"
android:icon="@mipmap/ic_link"
app:showAsAction="never" />
<item android:id="@+id/action_settings"
android:title="Settings"
android:visible="true"
android:icon="@mipmap/ic_settings_black_24dp"
app:showAsAction="never"
>
</item>
<item android:id="@+id/action_crlf"
android:title="@string/action_crlf"
android:checkable="true"
android:checked="false"
android:visible="false"
app:showAsAction="never" />
<item android:id="@+id/action_customer"
android:title="Link Aadhar"
android:icon="@mipmap/ic_card"
app:showAsAction="collapseActionView"/>
<item android:id="@+id/action_bank"
android:title="Policy Purchase"
android:visible="false"
app:showAsAction="collapseActionView"/>
<item android:id="@+id/action_buy"
android:title="Get Device"
android:visible="true"
android:icon="@mipmap/ic_shopping_cart_black_24dp"
app:showAsAction="never" />
I use a custom theme. Here is my theme style
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorAccent">@android:color/holo_blue_light</item>
<item name="android:colorPrimary">@android:color/holo_blue_light</item>
<item name="android:windowBackground">@android:color/background_light</item>
<item name="android:windowActionBar">true</item>
</style>
In AndroidManifest I have included this AppTheme. I have also checked if I have used multiple Launcher intent or not Please have a look at the Manifest
<application
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TerminalActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
</intent-filter>
</activity>
</application>
After failing to get any solution or understaning what I am doing wrong, I tried to follow the instructions from several Stack overflow answers.
Here are some of the random things I did:
Modified the default icon size in dimens.xml
<dimen name="design_navigation_icon_size" tools:override="true">24dp</dimen>
All my menu icons are 24dp. I though may be that could be a problem as Android probably expects a 48dp icon for mdpi. So I checked by replacing few icon with even 48x48 icon size or even 96x96 size.
I tried to checnge the color to icons in runtime to see if the icons are redrawn.
@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_terminal, menu);
for(int i = 0; i < menu.size(); i++){
Drawable drawable = menu.getItem(i).getIcon();
if(drawable != null) {
drawable.mutate();
drawable.setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
}
}
actionConnect = menu.findItem(R.id.action_connect);
actionDisconnect = menu.findItem(R.id.action_disconnect);
camPulseMenu= menu.findItem(R.id.action_pulse);
menuActivityTracking= menu.findItem(R.id.action_activity);
this.menu=menu;
return true;
}
All works fine in my debug but none in release build.
I also tried changing release settings in gradle. Here is my full gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.rupam.biosignal"
minSdkVersion 21
targetSdkVersion 23
versionCode 5
versionName "1.5"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
shrinkResources true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.macroyau:blue2serial:0.1.5'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.microsoft.projectoxford:face:1.2.5'
compile 'com.nabinbhandari.android.utils.permissions:android-permissions:1.0'
compile files('libs/dropbox-android-sdk-1.6.3.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/org.eclipse.paho.client.mqttv3-1.0.2.jar')
}
repositories {
maven {
url "http://dl.bintray.com/macroyau/maven"
}
}
My activity extends AppCompatActivity.
I know I am making some silly mistakes, but can't find it.
Can someone please help me understand what is wrong here? Why icons dont appeak in menus?
PS: I tested With Samsung Galaxy, Moto G, ViVO and about 7-8 such devices but without any luck.
You are Shrinking your resource in the release build.
please try to have the normal build type :
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}