0

I'm using a Toolbar (android.widget.Toolbar) set as ActionBar in my Activity (android.app.Activity) which has a menu item with an attribute android:showAsAction="always". So they are pure android classes without the appcompat (androidx.*) that I don't use app:showAsAction but android:showAsAction. It seems that there is no problem. But, Androidstudio warns like this screen shot:

Androidstudio warns android:showAsAction

My question: Are there any possibilities that android:showAsAction usage causes any problem?

build.gradle (:app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "test.showasactiontest"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.google.android.material:material:1.1.0'
}

MainActivity.java:

package test.showasactiontest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toolbar;

public class MainActivity extends Activity {

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

        Toolbar toolbar = findViewById(R.id.toolbar);
        setActionBar(toolbar);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".MainActivity">

    <android.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme" />
</FrameLayout>

res/menu/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:icon="@android:drawable/ic_menu_view"
        android:showAsAction="always"
        android:title="Item" />
</menu>
hata
  • 11,633
  • 6
  • 46
  • 69
  • Why don't you try that to see either it gives an error or not?! – MMG Mar 09 '20 at 08:00
  • @moein Of course I build it and it seemed no error caused. I'm questioning about any possibilities. – hata Mar 09 '20 at 08:03
  • So what is the problem? As you know Android Studio gives some warnings that have not effect on output. – MMG Mar 09 '20 at 08:05
  • 1
    @hata read this answer for detailed explanation https://stackoverflow.com/a/26378366/8035260 – jose praveen Mar 09 '20 at 08:11
  • @moein Then, I want to know and confirm that it is a wrong waring of lint. I'm supprised at the red underline. Awful. – hata Mar 10 '20 at 06:56
  • @Jose Praveen Thank you. Though I've known the way to use the appcompat library and I want do without it here, blackfizz's answer (https://stackoverflow.com/a/26377804/3501958) in that QA may be what I expect. – hata Mar 10 '20 at 07:03
  • Is my answer what you want? – MMG Mar 14 '20 at 04:23

1 Answers1

0

I think correct answer of this question will be your response:

Difference between android: and app: prefix in Android XML?

Your warning is for using android:showAsAction="always" instead of app:showAsAction="always"

android is usually used for attribute coming from Android SDK itself.

app is often used if you are using the support library.

MMG
  • 3,226
  • 5
  • 16
  • 43