How to get rid of title bar in android studio - android-studio

I am a very new programmer and I have just finished my first android app, I have a problem with the title bar. Ive googled and searched on stack overflow that if I changed the theme into notitlebar_ i will not have a title bar. However while that is true using the xml view, it is still present on the emulator, and also present when i ran it on my phone. (I also tried android:theme="#android:style/Theme.Black.NoTitleBar", but with the same results)
so how would i solve this? thanks in advance!!

Try something like this on the onCreate
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);

Here's the way that works best for me:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//hide the titlebar
getSupportActionBar().hide();
setContentView(R.layout.activity_main);

Related

How to set primary item after update to viewpager2 and FragmentStateAdapter?

I'm looking into an opensource project on github and it still currently makes use of ViewPager and FragmentStatePagerAdapter.
I'm trying to update it to use ViewPager2 and FragmentStateAdapter but there is some functions that I'm not sure about
public void setPrimaryItem(#NonNull ViewGroup container, int position, #NonNull Object object)
This was available as an override for viewpager but isn't anymore.
Any help?

How can I make a pop-up that appears on the screen when I open my application?

How can I make a pop-up that appears on the screen when I open my application? for example when i open camera, appears screen the pop up message.
You can make use of dialog to make pop-ups in your app
Step 1: Make a new layout file.
Step 2: Add The View which you want on your layout file.
Step 3: Add this code in your onCreate();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// you should set Id of your layout file here
myDialog.setContentView(R.layout.selection_theme);
myDialog.getWindow().setBackgroundDrawable((new ColorDrawable(Color.TRANSPARENT)));
myDialog.show();
And if you want to get Id of the Views on the dialog xml layout use
myDialog.R.id.Name_of_Your_View
if you want to close the pop up after you click on some view then use
myDialog.dismiss();
And of course you can name anything instead of myDialog,selection_theme etc

How do you dynamically load default HTML5 video thumbnails in Android WebView?

I've just recently started using Android Studio for the first time to develop a mobile app that simply loads my website and displays it. I added a WebView with WebSettings that enable JavaScript among other things and it works! However, video thumbnails do not display. Instead an ugly gray placeholder play button image is used. How do I make it so that the video thumbnails load like they would on desktop devices, or even in mobile browsers (because they do display there as well)?
I'm not entirely sure whether or not to include code in this question but I will share anyway :P
Here's the relevant snippets of the MainActivity.java file:
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDomStorageEnabled(true);
webView.loadUrl("https://example.com"); //My domain
}
}
So basically, it's either the preload="metadata" in my website's code or some equivalent attribute or CSS property that messes with Android WebView's autogeneration of video thumbnails, or it's because of my extreme newbieness to the whole Android app development thing. I'm willing to bet on the latter.
Also as a side question, should I store thumbnails on my server instead of having everyone's browsers load the 1st frame of every video every time?
Thanks in advance :)

Focus item listview on Android dosent work

I searched lot on internet to find a solution for my problem but I haven't found a answer. I hope someone can help me.
I have a Android application where I made a fragment with 3 tabs. Every tab had a different layout and in every layout there is a listview with different id. The problem is that, when i click on item of listview, only the item of the first tab take focus and background was set to green. In the other tabs the item is selected but focus don't change the background item color.
I had clear the focus on the first tab if was selected but this don't resolve the problem.
this is the code that I implementer on tab
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int pos, long arg3) {
view.setSelected(true);
selectedBusiness = businessList.get(pos);
buttonModify.setEnabled(true);
}
});
Any idea?
Thank Max
I found the solution.
The error in my case was made from
ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.my_business_item);
I don't know why but the problem was the layout. In the other two tabs, I used the adapter with another layout android.R.layout.simple_list_item_1. With this layout the focus dosen't work. With my simple layout it works.

javafx2.0 - force refresh the scene

In my app, one scene having the popup dialog which consists of some fields and buttons. If you click on the button then I want to dismiss the popup dialog as well as update the some fields in the scene. Indirectly I want to refresh scene. is it possible?
I used the following code.Here what I did is, I get the controller of that scene and then update the field using id. but it doesn't work.
URL location = AdmincontrolController.class.getResource("admincontrol.fxml");
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(location);
fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
try {
Parent root = (Parent) fxmlLoader.load(location.openStream());
AdmincontrolController controller = fxmlLoader.getController();
System.out.println("AdmincontrolController: "+controller);
controller.setEmail(item.getEmail());
} catch (IOException ex) {
Logger.getLogger(Add_loginController.class.getName()).log(Level.SEVERE, null, ex);
}
Scenario:
scene
Popup - If we clicks on the add then we need to dismiss that dialog and change the email text on the previous scene.
As Alexander mentioned above, updating the underlying text property of the object you are using to display the email should Just Work. You need to make sure that you are working with the property (see Oracle Java FX Property Tutorial for more info). As a concrete example:
FXML
<Text fx:id="email" />
<TextField fx:id="emailInput" />
<Button onAction="#doSetEmail" text="Set Email"/>
In your controller, use the #FXML annotation to inject concrete instances of objects and set the handler to adjust the text:
Controller
#FXML
Text email;
#FXML
TextField emailInput;
#FXML
public void doSetEmail(ActionEvent ae) {
email.setText(emailInput.getText());
}
Alternatively, you could just bind the email text property to the email label property so that changes would automatically get propagated:
email.textProperty().bind(emailInput.textProperty());
You could do this in your controller initialize() method.
Now, the caveat to all this working depends on how you are handling the event and what you are doing in this. You still haven't posted the code for that as requested by the first answer, so you may be having issues there. Namely, if you are starting threads and then trying to update UI elements on the JavaFX thread from a worker thread, then you can get into trouble (potentially) with things not updating. This depends substantially on the structure of your objects, and you have not given enough information to comment in any meaningful way on that.
chooks
Everytime you have the Feeling that you manually want to update a Scene you should probably use a backgroundWorker Thread to do the work.
This way your UI Thread can use the time to update Labels etc.
JavaFX is built so that you don't need to directly call the scene update routine. All you need - update properties of scene components, and they will be updated on the nearest pulse.
So, all you need is to update properties. Or, is there any real trouble?
refreshing scene its not possible without closing...but if you can do class level declaration for control..i.e make them static its may work...
try this..
make a function in main file.
MainPanel.java
public static void SetMail(String email)
{
txtmail.setText(email);
}
LoginPanel.java
btnclear.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
MainPanel.SetMail(txtEmail.getText());
}
});

Resources