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.
Related
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
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
I've got a Main Activity which is a search interface, when the user clicks a result in the list, the result details are displayed in a Fragment. The Main Activity has an Action Bar, but in the details Fragment, the Action Bar is hidden. To hide the Action Bar in the Fragment, I'm calling a method in the Main Activity from the Fragment Activity like this: ((SearchInterface)getActivity()).hideABar();. Then when the user clicks the back button, they go back to the search interface and the Action Bar reappears. Doing that is a bit more complex than simply calling a method. I set up an Interface in the Main Activity and override the method in the Fragment like this:
Main Activity:
public interface Callback {
public void onBackPressedCallback();
}
#Override
public void onBackPressed() {
super.onBackPressed();
if(fragBackPressed != null)
fragBackPressed.onBackPressedCallback();
checkActionBarState();
}
...
public void checkActionBarState(){
bar_AB = getSupportActionBar();
boolean barVisible = bar_AB.isShowing();
if(barVisible){
Toast.makeText(getApplicationContext(),"ActionBar WAS Visible",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"ActionBar WAS NOT Visible",Toast.LENGTH_LONG).show();
bar_AB.show();
}
}
Fragment:
#Override
public void onBackPressedCallback() {
Log.d("SSIVideoFrag", "checking action bar state");
}
So now, when the user presses the Back button while in the Details Fragment, they go back to Main Activity and the Action Bar reappears. Now I'd like to add a button in the Details Fragment that does what clicking the Back button does, but I can't figure out how to do it. I don't know how to override the onBackPressedCallback() method from within the onClick of a Button:
back_BTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//--- what to do here?
}
});
simple:
getFragmentManager().popBackStack();
https://developer.android.com/reference/android/app/FragmentManager.html#popBackStack()
ps.: that's not an actual back press, your onBackPressed will not be called. But the fragment will be removed, just like in a back press.
in my app i am developing an activity using the actionbar in NAVIGATION_MODE_TABS-mode.
Each tab is showing a fragment (list, detail).
Initially the list-tab is visibile.
The list is implementing setMultiChoicheModeListener() and modifies the ActionBar and the title of the activity if one or more items are selected.
How can i reset the title and the ActionBar to the inital value (title and actions) when the user clicks on the detail-tab without deselecting the items?
BTW Target-Platform is > 4.1 and i am not using the support library.
Thanks.
public class MyActivity extends Activity {
#Override
protected void onCreate (Bundle savedInstanceState) {
this.actionBar = getActionBar();
this.actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
....
for (Tab tab : getTabs())
{
//here are two tabs added (List and Detail)
this.actionBar.addTab(tab);
}
....
}
protected class NavigationTabListener implements ActionBar.TabListener {
private Fragment fragment;
....
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(newFragmentResourceId, this.fragment);
}
}
}
public class MyListViewFragment extends LinearLayout implements IListViewFragment {
....
#Override
public void initialize() {
inflate(getContext(), listLayoutResourceId, this);
this.myList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
this.myList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
....
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(selectedItemsMenuResourceId, menu);
return true;
}
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked)
{
if (checked)
{
this.numberItemsSelected++;
adapter.setNewSelection(position);
}
else
{
this.numberItemsSelected--;
adapter.removeSelection(position);
}
mode.setTitle(getContext().getResources().getQuantityString(
R.plurals.items_selected, this.numberItemsSelected,
Integer.valueOf(this.numberItemsSelected)));
}
....
}
}
I am trying to implement the MVP pattern, but it's still in evaluation phase. The Activity acts as the presenter, the views are in separate classes.
For each Fragment i am also implementing the MVP apttern, but i think this is not interesting to solve the problem.
Some notes to the classes:
MyActivity creates two fragments (one for List, one for Detail view, the detail view has nothing to do with the selected items).
The initial view of the activity is the fragment with the list.
If the user selects some entries I am updating the action bar and the title through the callback of MultiChoiceModeListener.
But the user can now change the fragment by clicking on the "Detail" tab without deselecting the items or clicking to the new elements in the action bar, the result is that the detail fragment is shown, but the title of the activity is still the one I modified in the MultiChoiceModeListener, and there is also the check mark of the action bar visible (auto created by the system).
So the best way is I think to get somehow the current ActionMode, so I can invoke finish() to "reset" the ActionBar and the title.
Make sure you keep reference of the ActionMode in the ActionMode.Callback methods inside your activity which has the ActionBar.TabListener.
When a new tab is selected just finish the action mode, like:
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if(mActionMode != null){
mActionMode.finish();
}
ft.replace(newFragmentResourceId, this.fragment);
}
Make the ActionMode reference back to null when onDestroyActionMode(ActionMode) is called.
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);