0
I created a Class external call Useful to leave some methods that I always use, but is giving error when using them, follows code from Useful:
package com.hs.gui.testelayout.util;
import android.support.v7.app.AppCompatActivity;
/**
* Created by Gui_j on 25/04/2016.
*/
public class Util extends AppCompatActivity {
public void backAppBar(String telaTitulo){
//getSupportActionBar() são métodos nativos do _Android_ que chamam um botão na tela
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle(telaTitulo);
}
}
if I keep it the way it is there, I have an error of return:
To make the mistake I should make
public void backAppBar(String telaTitulo){...}
in
public static void backAppBar(String telaTitulo){...}
But by doing so I earning another mistake:
That to correct I must remove the static
added, but with that we return to the initial problem.
About the getSupportActionBar()
Where is this method "getSupportActionBar()"? if it is from the Util class, it should be static as well.
– mau humor
It would not be better to pass the context as an argument to retrieve the actionbar from it instead of creating a class that extends actionbar?
– user28595
@user5978 the method is in the library, I import it here
import android.support.v7.app.AppCompatActivity;
– Guilherme HS
@Diegof as so?
– Guilherme HS
The method is not static. You cannot access a non-static method within a static method. Unless you have an instance of the object in question. You can instantiate the Appcom object..., or take it as a parameter, instead of extending it.
– mau humor
Instanciar Util, I believe it is the worst solution among the already suggested here.
– mau humor