Removing Title from the actionbar in Android 3.0 - java

I have a requirement in which I have to make an application that works from Android 3.0 onwards. Naturally I didnt go for ActionBarSherlock.
Now I replaced the background of the actionbar using the following code from the official google resource .
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/navigation_bar</item>
</style>
As a result , I now have the proper action bar .
Now the problem is , when I press the home icon ( ic_launcher.png) , when the icon is in pressed state I see the activity title and a carrot sign appear . I do not want such. I just want the home button to be clickable and would like to see nothing while the button is pressed .
I did succeed in removing the activity title that appears by using
getActionBar().setDisplayShowTitleEnabled(false);
however the default "<" sign still appears when the home icon is pressed .
Question 1 : How can I remove the "<" sign when the home icon is in pressed state
Question 2 : How can I remove the default options icon (on the right side , the three dots) ?
Thanks a bunch

For home Icon remove
getSupportActionBar().setIcon(R.color.transfrant);

Remove the title bar
in manifest under the activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
Change the action bar name. Android manifest under the activity
android:label="#string/app_name"
change to
android:label=" "

Question 2 : How can I remove the default options icon (on the right side , the three dots) ?
remove this method from your Activity class
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}

Related

ActionBar in Android overrides the BottomNavigation

When trying to change an icon to a downloaded drawable (or actually changing to any other icon during runtime), the icon changes once on the ActionBar.
I actually want to remove the ActionBar and leave only the bottomnav (tabs) for navigation, yet whatever i'm doing the icon changes only on the ActionBar.
The item inside bottom_nav_menu.xml:
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/ic_dashboard_black_24dp"
android:title="#string/title_notifications"
app:showAsAction="ifRoom"/>
The code that changes the icon:
#Override
public boolean onPrepareOptionsMenu (Menu menu){
menu.clear();
getMenuInflater().inflate(R.menu.bottom_nav_menu, menu);
menu.getItem(2).setIcon(this.bitmap_pic);
Log.e(TAG, "Icon Changed");
return super.onPrepareOptionsMenu(menu);
}
The result - Icon stays blank on BottomNav but appears on the ActionBar.
Expected result: BottomNav icon will be the image that shown on the top right.
Thanks
EDIT!
Issue was fixed after inflating the main_activity layout that contains the BottomNavView
Now the problem the picture isn't showing properly, attached a screenshot (Image is grey instead of showing the icon like in the ActionBar in the first picture):
Edit 2
Icon is still grey instead of showing the bitmap picture.
Added:
MenuItemCompat.setIconTintMode(bottomNavigationView.getMenu().getItem(2), PorterDuff.Mode.CLEAR);
But it still shows up like in the picture below
Edit 3
Fixed the issue using:
bottomNavigationView.setItemIconTintList(null);
I'm not sure if onPrepareOptionsMenu invoked for bottom navigation bar.
You should have to update navigation menu icon from onCreate method of that Activity.
Refer below code,
val menu = navigation.menu
val menuItem = menu.findItem(R.id.navigation_notifications) // find particular menu-item using its ID.
menuItem?.icon = this.bitmap_pic
Solution for Gray icon tint,
add below line.
MenuItemCompat.setIconTintMode(menuItem, PorterDuff.Mode.DST)

ViewPager on activity with dialog theme

I have an activity with a dialog theme (Theme.AppCompat.Light.Dialog.Alert)
Inside this activity i created a ViewPager because i want one image slider.
But my ViewPager create something like an actionBar before the slider. How can i remove it?
If my activity had an normal theme (not like a dialog) i could hide it doing the following code:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
But it doesn't work in a dialog theme....
EDIT
My problem:
I want remove the "PageViewExample" =/
i already tried the following string and nothing happens
requestWindowFeature(Window.FEATURE_NO_TITLE);
I just added some style to my theme.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

The following classes could not be instantiated: - android.support.v7.widget.Toolbar

I am creating an app with the new Material Design used in Android Lollipop (5.0).
I am using the following guides:
http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
http://antonioleiva.com/material-design-everywhere/
After I create my toolbar, I receive this error: "The following classes could not be instantiated:
- android.support.v7.widget.Toolbar"
The app works well in the phone or emulator, but the layout designer of Android Studio doesn't show the layout correctly.
Here there are some images:
Error in my_awesome_toolbar.xml layout preview
Error in activity_my.xml layout preview
The xml code of the files:
my_awesome_toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
activity_my.xml:
<RelativeLayout 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"
android:id="#+id/root"
tools:context="com.myapp.test.MyActivity"
android:orientation="horizontal">
<include
android:id="#+id/toolbar"
layout="#layout/my_awesome_toolbar"
/>
<!-- Rest of layout -->
</RelativeLayout>
MyActivity.java:
package com.myapp.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
xml code of the styles (values/styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="actionOverflowButtonStyle">#style/AppTheme.OverflowButtonStyle</item>
</style>
<!-- Style Title -->
<style name="Title">
<item name="android:textColor">#color/white</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
<style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/overflow_icon</item>
</style>
</resources>
At the moment I use Android Studio Beta 0.8.9
I changed the res/values/styles.xml file from this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
and that solved the problem.
For Android Studio (or IntelliJ IDEA),
If everything looks OK in your project and that you're still receiving the error in all your layouts, try to 'Invalidate caches & restart'.
Wait until Android Studio has finished to create all the caches & indexes.
I did what #gbero said, and I changed the Android version number that Studio uses from 22 to 17 and it works.
I am using the backwards compatibility to build for Android ver 22 but to target 17 (idk if that's correctly said, I am still trying to figure this app stuff out) so that triggered the backwards compatibility, which afaik is what the android.support.v7.* is. This is probably a bug with their rendering code. Not sure if clearing the cache as suggested above was needed as rendering didn't work just after invalidating the cache, it started working after I changed the version to render. If I change back to version 22, the rendering breaks, if I switch back to 17, it works again.
From: https://stackoverflow.com/a/29989542/4123403
Clean project
Rebuild project
Sync Gradle
This did the trick for me.
Another mistake that can have the same effect can be the wrong theme in the preview.
For some reason I had selected some other theme here. After choosing my AppTheme it worked fine again:
Sorry if I answer myself, but, at the finally, the solution of my problem was update Android Studio to the new version 0.8.14 by Canary Channel: http://tools.android.com/recent/
After the update, the problem is gone:
I leave this question here for those who have this problem in the future.
Clean project
Rebuild project
Sync Gradle
it work for me
I did what #ang_lee said and also i added this line to the app theme style :
<item name="windowActionBar">false</item>
i am using version 26.0.1 :
com.android.support:design:26.0.1
com.android.support:appcompat-v7:26.0.1
building tools:
buildToolsVersion "26.0.1"
I had the same error on my Android Studio screen when i wanted to prevew my project. I fix the problem by this ways:
1- I chang the version from 22 to 21. But if I change back to version 22, the rendering breaks, if I switch back to 21, it works again. Thank you #Overloaded_Operator
I updated my Android Studio but not working. Thank you #Salvuccio96
I had the same problem for one of the activities in my app , one of the causes of this problem is that Theme in the theme editor might be different than the theme defined in the 'styles.xml'.change the Theme in the theme editor to your 'Apptheme' or your custom defined theme(if you have defined). Doing this fixed my issue.
none of above worked for me ,
i updated the appCompat - v7 version in my app gradle file from 23 to 25.3.1. helped to make it work for me
Find styles.xml in app/res/values folder.
Parent attribute of the style could be missing "Base".
It should start as
<style name="AppTheme" parent="Base.Theme.AppCompat...
I had the same error. Eventually I got this notice that a plugin was out of date:
After I updated, the problem went away.
The solutions above didn't help me. I've tried 2 first steps from
this link.
Worked fine for me.
But don't forget to
import com.melnykov.fab.FloatingActionButton;
instead of
import android.support.design.widget.FloatingActionButton;
in your MainActivity.java
I use android studio 2.3.3:
- Open styles.xml
- Android studio will show a notification on the top right with two options: "open editor" and "Hide notification".
- Click "open editor"
- Under theme parent dropdown, click show all themes
- Select any theme starting with AppCompat... (I used AppComat.DayNight)
NB: If your title bar disappears, you need to extend AppCompatActivity instead of Activity.
All the best!
My Problem has also been solved by changing in styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Up Navigation - transition does not slide from right to left

I've created some custom transitions so when a button is clicked the pages slide in and out. This works perfectly for when a page is entered (slides from left to right) and when the back button is clicked (slides from right to left) but when the "up" button is clicked in the action bar, the page slides from left to right when I want it to behave like pressing the back button. Here's is the code I am using in the styles.xml file:
<style name="YourAnimation.Activity" parent="#android:style/Animation.Activity">
<item name="android:activityCloseEnterAnimation">#anim/slide_in_left</item>
<item name="android:activityCloseExitAnimation">#anim/slide_out_right</item>
<item name="android:activityOpenEnterAnimation">#anim/slide_in_right</item>
<item name="android:activityOpenExitAnimation">#anim/slide_out_left</item>
</style>
Any help would be appreciated. Thanks!
You could try using overridePendingTransition() but you'd have to insert it everytime you switch activities.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
super.onBackPressed();
overridePendingTransition(R.anim.enterAnim, R.anim.exitAnim);
return true;
...
You'd also might want to check how you implement onClick() for the up-button. Here I'm calling super.onBackPressed() which calls finish() on the activity.

Android : Menu Item always overflows in portrait

I am developing an Android application which uses SlidingMenu and
ActionBarSherlock.
I want to include a MenuItem in a particular SherlockListFragment which
onClick would refresh the content. The issue I have is that the item always
overflows even though there is plenty of space. When the device is turned to
landscape orientation the item moves into the ActionBar automatically.
Can anyone help with this issue? I have set the showAsAction to "always" but
still the issue is not fixed.
This is the XML file for the menu
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_refresh"
android:title="S"
android:showAsAction="always"
/>
</menu>
This is the code in the SherlockListFragment
#Override
public void onCreateOptionsMenu(Menu menu,
com.actionbarsherlock.view.MenuInflater inflater) {
inflater = getSherlockActivity().getSupportMenuInflater();
inflater.inflate(R.menu.fragment_news,menu);
super.onCreateOptionsMenu(menu, inflater);
}
This is what the application is currently looking like:
I need the button in the ActionBar
try to set an icon
android:icon="#drawable/ic_menu_done_holo_light"
OR use flag withText
android:showAsAction="withText|always"

Categories