How to change the title bar inside a fragment? Somewhat I am not able to succeed.
setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);
I think the problem is that you can't access the ActionBar APIs from the fragment. So, what you need is an access to the Parent Activity.
Try : getActivity().setTitle("My new title");
Related
My android app has a toolbar and I wan to change the title of it. I used toolbar.setTitle() but it is not working... Please help. What should I do? I tried getSupportActionBar().setTitle() but it doesn't work.
Try to use this.setTitle(title); in onCreate() method.
Use below code to set the title
Toolbar mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mActionBarToolbar);
getSupportActionBar().setTitle("My title");
I've been trying to get a widget from another layout for past hours but still no luck. Can someone tell what is wrong with my current code?
public void refreshClicked(View view){
tab1 = LayoutInflater.from(view.getContext()).inflate(R.layout.tab_1, null);
Button b = (Button) tab1.findViewById(R.id.refresh);
b.setText("Updating...");
}
I've hooked my button onClick to refreshClicked(View view) method.
This method is under my MainActivity.java and I'm trying to get the Button with id refresh from tab_1.xml layout but the button text is not updating.
Thanks!
You seems to inflate a layout but never attach it to a parent view as the ViewGroup parameter is null. Then this layout inflated must not even been displayed anywhere.
If the button b already exists, no need to inflate the layout and retrieve the button form there, it will a different button.
Just retrieve the button from the actual existing layout.
Check out this picture:
WhoKnew title and WK? Icon http://puu.sh/5Ejo5.png
See the icon and title there? How do I go about removing that?
I'm not using any of the drag and drop or xml editing at all in eclipse for this project, because I have to dynamically create an arbitrary amount of buttons/text, and whatnot.
Basically, I've been going about it by doing something like this..
public createMainMenu(){
//make layout
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(backgroundColor);
//make/add text to layout
menuText.setText("Who Knew?");
menuText.setId(20001);
menuText.setTextSize(36);
menuText.setTextColor(textColor);
layout.addView(menuText);
//make a scrollview, then add the layout to the scrollview
ScrollView sc = new ScrollView(this);
sc.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
sc.setFillViewport(true);
sc.addView(layout);
//set content view to the scrollview
setContentView(sc);
}
Hopefully, I'm on the right track here on how I should be going about this. The app I have is working fine, I just need to get rid of that icon/title bar, if possible. I guess it's not a gamebreaker, but it's a bit annoying.
you can use this in your java class
requestWindowFeature(Window.FEATURE_NO_TITLE);
Add this to your manifest:
android:theme="#android:style/Theme.Light.NoTitleBar"
I want to add a a menu item to the top (Where the class title is). I added the item to menu.xml and also for made an Intent to open a new class after clicking but it does not open my whole app anymore. And when I remove android:onClick:"history" it starts working again with out the menu function of course.
Have a look at the picture please: http://snag.gy/udxXc.jpg
That 'History' is my button that needs to open a new class. and this is my code:
xml:
<item
android:id="#+id/history"
android:showAsAction="always"
android:title="History"
android:onClick="history"/>
Java:
public void history(View view){
Intent historyIntent = new Intent(this, History.class);
startActivity(historyIntent);
}
Am i doing it correctly? or any better solution?
I want to add a a menu item to the top (Where the class title is)
That is called the action bar.
And when I remove android:onClick:"history" it starts working again with out the menu function of course.
I am not aware that android:onClick is valid for <item> elements.
Am i doing it correctly?
Not as far as I am aware.
or any better solution?
Override onOptionsItemSelected() and respond to the item click there.
I am using ABS for my application. But I do not want my start screen (the first activity) to have action bar. How should I modify the theme to achieve this?
Many thanks in advance.
You could set your activity's theme attribute in AndroidManifest.xml file to one of the following based on your requirement:
android:theme="#style/Theme.Sherlock.Light.NoActionBar"
android:theme="#style/Theme.Sherlock.NoActionBar
call hide() on your ActionBar object, inside the onCreate() of your FirstActivity
if you are using Sherlock
getSupportActionBar().hide();
add following code in your activity :
ActionBar ab = getActionBar();
ab.setDisplayShowTitleEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.hide();