hide activity name from action bar just in time of creation - android

Just in time of creation and for about one second or less the action bar shows the name of activity as declared in manifest. Is there any way to avoid this? Of course when activity is created i change programmatically the title.The manifest:
<activity
android:name="com.abc.HomeActivity"
android:screenOrientation="portrait"
android:label="Home"
android:icon="#drawable/x_logo">
</activity>
and code from fragment which is shown by activity. I change the title of action bar based on what fragment is shown.
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("variable name");
from activity:
super.onCreate(savedInstanceState);
getSupportActionBar().setTitle("");

If hiding the activity name means simply avoiding the text, then call the following in onCreate of your Activity:
getActionBar().setTitle(null); //if using ActionBar theme
setTitle(null); //if using standard theme
Update
#Override
protected void onCreate(Bundle savedInstanceState) {
...
final CharSequence title = getActionBar().getTitle();
getActionBar().setTitle(null);
//sets the title again after 1 second delay
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
getActionBar().setTitle(title);
}
}, 1000);
}

Use this line to hide a name of activity this.requestWindowFeature(Window.FEATURE_NO_TITLE);
just after onCreate.
Example.
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.serverfilelist);

Related

ActionBar Back Button and Title

I have an activity that I would like the "up affordance" on.
public class ItemListActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
// ...
}
}
This adds the "back button" like I want. The problem is that the Title is not considered part of the back button in this instance. Is there any way to make it so that it behaves more like the Messaging app? In the Messaging app you can tap either the back button or the title and it will take you back to the previous activity.
Add an onClickListener to the title of your ActionBar. See this post for example: Set OnClick Listener on Action Bar Title in Android

click home button in fragment page to disappear action bar activity title

I am facing weird issue.I am using PageActivity inside three
fragments swipes one after another and so on.
My problem is,when I am in FragmentA page,on click the home
button ,again come back to the application, my action bar title name is
Chapter,which I was added the action bar title name in PageActivity and
after 2 seconds the fragment title was loading with the help of
query.
My only problem is,on home button click in fragment page instead of
activity title name,Fragment page title name have to be shown
directly after enter the application.
Below I am posted the code related to this:
PageActivity.java:
public class PageActivity extends FragmentActivity {
static TextView mTitleTextView;
.......
.......
#Override
protected void onResume() {
super.onResume();
ActionBar(Constants.Titlebarcolor);
........
........
}
public void ActionBar(String color) {
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mTitleTextView = (TextView) mCustomView.findViewById(R.id.textviewHeading);
mTitleTextView.setText("Chapter");
}
FragmentPageA.java:
#Override
public void onResume() {
super.onResume();
....
....
}
#Override
public void onPause() {
super.onPause();
....
....
}
#Override
public void setMenuVisibility(final boolean visible) {
//get action bar title for every fragment page
PageActivity.mTitleTextView.setText(DatabaseQueryHelper.getInstance().getPagename(getArguments().getInt(Constants.PAGEID)));
......
......
}
Anyone can give me any suggestion regarding to this.Thank you.
I just moved this ActionBar(Constants.Titlebarcolor); line inside onResume() method to onCrate() method.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar(Constants.Titlebarcolor);
}
So that When I entering into the activity,the action bar activity title will not resume.

Android unable to hide title bar

I have a fragment that shows a camera preview and a button, and in the activity for the fragment I'm trying to hide the title bar, but it doesn't work. The title bar still shows. In the activity:
#Override
public void onCreate(Bundle savedInstanceState) {
// Hide the window title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Hide the status bar and other OS-level chrome
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
}
I'm following the book Android Programming: The Big Nerd Ranch Guide.
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Make this activity, full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the Title bar of this activity screen
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
...
}
In manifest change this
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

Android: Not able to change image in Window Title

I have a parent activity (from which all other activities extend) - with a 'Navigation Drawer Toggle' icon in window title.
I want to change the 'Navigation Drawer Toggle' image everytime drawer icon is clicked ( to open/close drawer)
public class ParentActivity extends Activity {
private ImageView imgDrawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
....
setContentView(R.layout.window_title);
imgDrawer = (ImageView)findViewById(R.id.imgdrawer);
...
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_title);
}
...
public void openDrawer()
{
...
//Switch Image
imgDrawer.setImageDrawable(getResources().getDrawable( R.drawable.ic_close_drawer));
}
public void closeDrawer()
{
...
//Switch Image
imgDrawer.setImageDrawable(getResources().getDrawable( R.drawable.ic_open_drawer));
}
...
}
Problem is that the 'imgDrawer' is not changing, when openDrawer and closeDrawer is invoked.
Is this becz the 'imgDrawer' icon is in window title or something else?
Probably setContentView and setFeatureInt layout is same and calling getWindow().setFeatureInt before setting layout for Title. do it as:
#Override
protected void onCreate(Bundle savedInstanceState) {
....
setContentView(R.layout.window_title);
...
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_title);
imgDrawer = (ImageView)getWindow().findViewById(R.id.imgdrawer);
}
or pass a layout which contain ImageView with different is from setContentView layout

How to set icon to title bar for each Activity in TabLayout

In my tablayout example, i have created 3 tabs, as usually i set 3 activities for each tab. I can set image to title bar of activity, which adds the intent to each tab. Due to this, the image in the title bar is visible in all 3 tabs. My requirement is to set a different image to title bar for each activity. I followed this to set image to title bar. But when i am going to do the same thing to each activity, getting android.util.AndroidRuntimeException: You cannot combine custom titles with other title features this error and application is terminated.
manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aptitsolution.tablayout"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/MyTheme">
<activity android:name=".TabLayoutDemo"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="AlbumsActivity"></activity>
TabLayoutDemo.java
public class TabLayoutDemo extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, ArtistsActivity.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
....
....
ArtistsActivity.java
public class ArtistsActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//i am getting the error here
setContentView(R.layout.artists);
setFeatureDrawableResource(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
}
}
my_title.xml
<RelativeLayout android:id="#+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:src="#drawable/nowplaying"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#+id/title" android:layout_width="wrap_content"
android:text="New Title" android:layout_height="wrap_content"/></RelativeLayout>
thanks
venu
Hello You cannot use Custom Title feature from activities that are nested in TabHost.
That is if you are requesting Custom Title from Activity A and Activity B which are nested in TabActivity Android will throw the exception you mentioned above.
Work around to this issue is to let TabActivity request custom title. And change content of Custom Title of TabActivity from inside the Activity A and Activity B.
Another tip I can give you is override the onResume() call of Activity A and Activity B to change the TabActivity custom title.
EDIT : Sample Code
For your tab activity
public class TabLayoutDemo extends TabActivity {
//CREATING A PUBLIC STATIC VARIABLE
public static TabLayoutDemoInstance myTabLayoutDemo;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
TabLayoutDemo.TabLayoutDemoInstance=this;//STORING
//COMMENTING SET FEATURE IN TAB
//getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
//REST CODE REMAINS SAME
Now for your Activity A and B
public class ActivityA extends Activity{
//LOST MORE CODE ABOVE
#Override
protected void onResume() {
super.onResume();
//SET FEATURE FROM INSIDE ACTIVITY
TabLayoutDemo.TabLayoutDemoInstance.getWindow().
setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
}
}
Copy on resume of ActivityA specified above for B as well.
Tip: you can change change the title layout from each activity using this.
I hope that helps.
The (standard) title you can change easily with
implementing onChildTitleChanged in the TabActivity
#Override
protected void onChildTitleChanged(Activity childActivity, CharSequence title) {
super.onChildTitleChanged(childActivity, title);
setTitle(title);
}
set the title in the child activities, f.e.
#Override
protected void onResume() {
setTitle("Calender");
super.onResume();
}
Changing a custom title shouldn't be that hard with this strategy. F.e. all your child-activities could implement a interface and have a method
public int getTitleResource()
The tab-activity can now do
#Override
protected void onChildTitleChanged(Activity childActivity, CharSequence title) {
super.onChildTitleChanged(childActivity, title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, ((TabChild)childActivity).getTitleResource());
}
Or you can transport the id as part of the child-title-string and parse it back to int...
--------------------------- One more Action for the same --------------------
Step Declare instance of class:
Parent Tab Activity:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.tab_layout_title);
TabLayoutActivity.tabLayout = this;
TextView titleText = (TextView) findViewById(R.id.myTitle);
titleText.setText("Care");
Child Activity
#Override
protected void onResume() {
super.onResume();
TabLayoutActivity.tabLayout.titleText.setText("Title name");
}

Categories

Resources