I have Tab-bar and custom title-bar in same activity.In static mode am able to display tab-bar and custom title-bar in the same activity. But when i assign dynamic values to custom title-bar attributes it shows error as
AndroidRuntimeException: You cannot combine custom titles with other title features
Please provide any suggestions.
Thanks in advance
Try:
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
this.getActionBar().setDisplayUseLogoEnabled(true);
final LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflator.inflate(R.layout.header_bar, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.header_bar_title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
and make sure you do this before setContentView() method.
Related
I wanted to know how to add my own custom font to the app name that appears in the action bar in android studio.
You can set CustomLayout in ActionBar
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());
//assign the view to the actionbar
this.getActionBar().setCustomView(v);
You can assign the custom font to textview by using setTypeFace()
I did this by just making an image of the app name with the custom font then displaying the image as the logo in the action bar. Much simpler.
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.app_logo);
I show a DialogFragment from another DialogFragment. I need to set title and a button just next to it. I don't want to reimplement the theme and create a custom view inside DialogFragment's content view instead of dialog title (because it's error-prone and time wasting). Is it even possible? I tried many API functions, AlertBuilder, ActionBar, this and that, still didn't found anything that fits my needs.
Try something like this:
// Title
final int titleId = getResources().getIdentifier("alertTitle","id","android");
TextView title = (TextView) popup.findViewById(titleId);
title.setText("My new title");
// Title's parent layout
ViewGroup viewGroup = (ViewGroup) title.getRootView();
// Button
Button button = new Button(this);
button.setText("A Button");
viewGroup.addView(button);
Note: You may need to adjust the button and title objects' LayoutParams.
An update. This can be achieved by calling setCustomTitle on AlertDialog.Builder class. Available since api level 1, and do not require a bunch of code.
Example:
AlertDialog.Builder(getActivity()).setCustomTitle(getActivity().getLayoutInflater().inflate(R.layout.my_custom_view, viewGroup)).create()
I have a custom title bar, a simple relative layout, that I set as the custom title bar of my activity. But at want the android BackAsUp icon < to show up as usual (i.e. to the left of my custom layout). How do I do that? here is my code so far.
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.my_title_bar, null);
this.getActionBar().setCustomView(v);
Update:
I have tried the answer at Remove Icon but have HomeAsUp in ActionBar they don't work. So one question, is order of setting those flags matter?
Adding the following combo solved the problem.
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
this.getActionBar().setDisplayShowHomeEnabled(true);
I just started playing with the new support library with ActionBar support. I'm trying to implement a bar that looks basically identical to the Ice Cream Sandwich layout on the edit contact screen. I understand I probably need to implement a custom view something similar to this - How to display custom view in ActionBar?. What I don't understand is exactly what that view is, and the best way to implement it.
Here's the screenshot of what I want in my actionbar:
Is that just a view with an image and some text, or a styled button, or something totally different? It has some state pressed properties.
Thanks for the help.
You can try using a custom view, by adding the following code when you want the button to appear :
// Inflate the view from XML file
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);
// Tell the view to occupy the whole actionBar view (MATCH_PARENT)
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
getActionBar().setCustomView(v, layout);
i want to add Layout Dynamically on Add button click and on Dynamic Layout show Datepicker,Timepicker Dialog and set value in given Edit Text. show in image on Date Click set Date Right side . Here problem Start when Add Second Same layout and set date it set only on newly created layout
For example you need to create xml layout file with ScrollView and LinearView inside.
Then in your Activity class:
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View main = inflater.inflate(R.layout.your_layout, null);
setContentView(main);
LinearLayout linear = (LinearLayout)main.findViewById(R.id.linear_layout);
and then in onClick method just:
View yourView = inflater.inflate(R.layout.yourView, null);
// Do whatever you want with your View, set up some variables etc.
and to add your view to main view:
linear.addView(yourView);
I know that this is not a direct answer to your question, but maybe will help you with dynamically adding Views.