Dynamic style change in tabhost - java

Sorry for my awful English.
There is an application in android TabHost. Tabs include Activity.
In the application I use the menu compile from prefs.xml
How can I change dynamic font size in activity only??

You can alter text size using this:
int size = 12;
TextView textView = findViewById(R.id.my_text_view);
textView.setTextSize(size);

Related

Change Android Drawable Button Icon Programmatically

How would one change the android:src XML property programatically of a FloatingActionButton or Button widget? I have a button defined as following within an activity:
FloatingActionButton floatingActionButton = (FloatingActionButton) this.findViewById(R.id.start_button);
It has an initial android:src set as follows:
android:src="#android:drawable/ic_media_play"
I'm trying to utilize the setImageResource(int id) to change the android:src XML property, but how to I access a Drawable icon such as ic_media_pause after a button click that occurs for example. When I try to pass in R.drawable.ic_media_pause to the setImageResource() method I received an cannot resolve symbol error.
floatingActionButton.setImageResource(R.drawable.ic_media_pause);
How do I get at the available R.drawable resources to pass it in as an argument.
Any help would be great appreciated. Thank you!
You're trying to access a default icon included in the SDK. You need to prefix your resource identifier with "android." For example:
floatingActionButton.setImageResource(android.R.drawable.ic_media_pause);
this will allow you to reference the default icons.
:)

Android tab bar with different fragments and different action bar icons

Problem Description and Question
I'm using tab activity with action bar. In the HOME tab I have GridView which contains some items, like it is shown in the image below (Hot Lines, Taxi, Restaurants etc)
Wen user click on the items in the grid view I want my application to take following actions:
Change icon of application to grid view item image on which I pressed.
Change the test near the icon
Add standard back button near icon, which will go back to grid view screen.
Change the tab fragment to the one which I specify.
Like it is shown in the image below:
As I never deal with this kind of problems can you please give me example or share some link with me of how I can do this? and can I do this at all?
This might help:
Android studio - is possible to add tabs pointing to fragments from designer?
It is not exactly what you want, but a good start. If you are willing to put a bit of work in it, you should be able to get what you want. If you have a basic Frame to work with and more specific problems with this matter I will gladly help you out ^^
John
The first link you can check is THIS.
And you should read more about ActionBar.
The last thing is it's better if you google it first and try to write a code and when you got stuck somewhere share your code with us and ask for help.
You have to use actionbarsherlock library for it.
use android.support.v4.app.FragmentTabHost and TabWidget in the xml as shown below :
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
style="#style/yourstyle"/>
<FrameLayout
android:id="#+id/realtabcontent"
style="#style/realtabFrameContentStyle" />
<TabWidget
android:id="#android:id/tabs"
style="#style/yourtabstyle" />
</android.support.v4.app.FragmentTabHost>
Use SherlockFragmentActivity for showing the tabs.
In the activities code use following code (preferably in a function) to set the ctionbar icon and text :
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setCustomView(R.layout.your_action_barlayout);
((TextView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title))).setText("your title");
ImageView homeButton = ((ImageView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.your_icon)));
homeButton.setVisibility(View.VISIBLE);
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, YourHOmeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
activity.finish();
}
});
ActionBar mActionBar = activity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.show();
then call this function with your icon and your text in your fragments onResume() method.

java - radiogroup with on checked changed listener in fragment

I'm new to android programming. Maybe you can help me with this.
I've got:
Fragment
RadioGroup with 2 radio buttons
EditText
My goal is:
By default the first radio button is selected and the edittext was disabled or uneditable
then when i select the 2nd radio button it enables the edittext and setfocus to it
And also vice versa.
When i select again the first radio button it will disable the edittext.
This were all inside one of my fragments.
Can someone help me for the code?
Also another question, can i save the previously selected radio button using shared preferences so it will be loaded when i open my application?
Thanks in advance. :)
Ok first set your EditText in visible in xml or java using this code snippet android:visibility="invisible" or in java code myButton.setVisibility(View.INVISIBLE); while pressing the other radio button make it visible by using this code myButton.setVisibility(View.VISIBLE);
Then com e to your second question you can save your radio button selection using share preference by setting a variable
save
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("your_key", "yourValue");
editor.commit();
get
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
String myValue = sp.getString("your_key", "defaultValue");
The SharedPreference interface gives you access to the an xml file, and a easy way to modify it through its editor. The file is stored in /data/data/com.your.package/shared_prefs/ and you can access it onlu through this SharedPreference API

Dialog context issue - Android

I have created a dialog box like so using a custom layout:
dialog = new Dialog(FetchMenu.this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.custom_dialog_iab);
dialog.show();
I am now trying to edit a textbox within 'layout.custom_dialog_iab' for example:
TextView text = (TextView) findViewById(R.id.all_topics_unlock_button);
text.setText("Purchased");
My Question: How do I get the right context to be able to edit the textboxes?
P.S. I have tried 'dialog.getContext()' but still keep throwing null pointers?
You need to use:
TextView text = (TextView) dialog.findViewById(R.id.all_topics_unlock_button);
Note the dialog. in front of findViewById
regular findViewById() will search your activity layout rather than the dialog layout.

Adding buttons on xml file other than main

I have two xml files in my application - main.xml and options.xml.
In both of them I use buttons. The problem is, that while interacting with the buttons in main.xml, I cannot do that with options.xml: if I write
Button b = (Button)findViewById(R.id.b1);
, b is going to be null. What is the cause of this problem and how do I fix it?
Thank you in advance.
You need to either inflate the options.xml or set it as content view:
setContentView(R.layout.options);
before you can use the views in that layout file.
It sounds like you want to be able to access both layouts so you should do something like this:
View view = LayoutInflater.from(context).inflate(R.layout.options, null);
Button b = (Button) view.findViewById(R.id.b1);

Categories

Resources