Back button on action bar - java

when I create a new activity, Android Studio show me this photo:
It have a Back button but activity haven't it. how can I Make visible it?

put getSupportActionBar().setDisplayHomeAsUpEnabled(true); into onCreate() method in your activity class

In manifest declare the activity as a parent activity to get this button like this
<activity android:name="com.owletogroceries.activity.RewardsActivity"/>
<activity android:name="OrderConfirmationActivity"
android:parentActivityName="ProductActivity"/>

Related

Set an on click listener on button in a fragment in the main activity file

I have tried to do some research on the topic and I am attempting to add an on-click listener for a button in a fragment in the main activity. So when I click a button in a fragment the click can get registered in the main activity file.
You can use custom broadcast receiver
You will register a receiver on button click in fragment
Then in activity apply action if this broadcast action equal to this custom action
you can use interface for this problem

Cannot hide app from recent list when overview button clicks

I want to hide my A activity from recent list, and i used excludeFromRecents="true", it works fine when i select home button and then select overview button, but when A activity is showing and i press overview button, activity exists in recent list, how can i hide A activity in that situation?
here is my activity tag in manifest :
android:name=".A"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:screenOrientation="portrait"></activity>

Android dialog theme makes setContentView crash the application

I'm applying this theme from manifest :
<activity
android:name=".ui.rate.MyActivity"
android:theme="#android:style/Theme.Dialog">
</activity>
With this the application crash on setContentView() of MyActivity. If I remove it there is no crash but I need this theme
In the activity onCreate() i'm doing this :
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_rate);
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Even if I remove the first and third lines the applicatio ncrash the same way. It's really the dialog theme that's causing the crash
How can I set it so that Android accept it ?
You can use Theme.AppCompat.Dialog as the theme of your activity to avoid
compatibility problem.
The activity will be presented as a dialog.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Dialog">
</activity>
As for the title, you can use setTitle("Hola!"); to change it.
If you wanna remove the title, just call:
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#style/Theme.AppCompat.Dialog",
and:
requestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#android:style/Theme.Dialog".

Android - Should Navigation Drawer Activity be Home Screen in Android Applications?

I am learning Navigation Drawer. In most of the examples given on internet, fragments are used.
My requirement is:
Home activity should contain Navingation Drawer
When I click on any item in the navigation drawer, a new activity should get opened with the BACK arrow (<--)
When I click on the BACK arrow, again I come to the Home screen with Navigation Drawer
If I look into most of the applications installed on my mobile like PayTM, all are operating like this.
My Approach
I am adding a Navigation Drawer Activity and making it the MAIN activity in the Manifest file like this:
<activity
android:name=".NavigationDrawerActivity"
android:label="#string/title_activity_navigation_drawer"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Adding BACK button in all other activities which open from the menu items of this drawer like this:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_class);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Question: Should I make Navigation Drawer Activity as Home Screen and call other activities from here (By clicking on menu items on the navigation drawer)? Is this the right approach? Do other applications also use this approach which use Navigation Drawer? If this is not the best approach, then how should I implement my requirement? Do I need fragments as mentioned in almost all the tutorials of Navigation Drawer?
Thanks!
Common NavigationDrawer Across All Activity Example is here
refer below Link for that
Common NavigationDrawer
this is Example of open Activity from NavigationDrawer and if u extend BaseActivity than NavigationDrawer will implement on that activity and where u do not want navigation drawer, do not extend BaseActivity

Android notification bar persists on the all Application screen(never goes)

I have a screen in my app with a button to set date/time in the OS. I use startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS)) to open the android's date/time screen .
After setting the date/time , i return to my app screen using the back button in the android's status(notification) bar. After this, the notification bar never dissappears from my app screens. Its persistent until i restart my application. Is there a way to remove the notification bar?
I have added the line "android:theme="#android:style/Theme.NoTitleBar.Fullscreen" to all my activities and even at at the application level(just inside )
But still it never goes
Here is a part of my manifest
<activity
android:name="com.cyberonics.progsoundapp.ui.AlarmSettingScreen"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_alarm_setting_screen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
I also have the following code in my activity class
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) before SetContentView()
Is there anything else i am missing?
Request your guidance on this
Thank you

Categories