My question is the following, how do I go about removing a RelativeLayout containing buttons every time the user calls up the soft keyboard to type on an editText on the same layout. As you can see on my images below, the buttons within the red box need to disappear every time the user is inputing information and reappear after the keyboard has been called off.
FYI - The RelativeLayout needs to be fixed at the bottom when the keyboard is not in view so "layout_alignParentBottom='false' is not a solution for me. I think this most likely needs to be done programatically.
Any suggestions on how to tackle this problem would be highly appreciated.
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/activity_margin_zero"
android:background="#color/background"
android:minHeight="48dp"
android:padding="#dimen/activity_margin_zero">
Here is what Google Android Developer site describes as "Persistent Footer Button"
This is what I have but the so called "Persistent Footer Button" should disappear when the keyboard is on screen.
Buttons should be behind keyboard when it shows or disappear so that the user can input information with more screen real state.
Have you tried modifying the windowSoftInputModeproperty of your activity?
In your manifest, for the related activity, set the property like so:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
... >
</activity>
RelativeLayout footer = (RelativeLayout) findViewById(R.id.footer);
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
footer.setVisibility(View.VISIBLE)
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
footer.setVisibility(View.INVISIBLE)
}
}
Note: The above code will only called for virtual keyboard also check out this Listen for keyboard show or hide event in android
Related
I am making an android app where the same imageview is displayed every time the user enters a value. but I want the imageview to be changed every time the user enters a value. I wrote a code to do this but the problem is after the first image is displayed I face black screen and it takes me to the first page in the app, it doesn't crash just shows black screen.
here is the imageview code in xml file:
<ImageView
android:id="#+id/ImageSuccess"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip"
android:scaleType="centerInside"
android:src="#drawable/image1" />
and here where I changed the imageview in java file:
ImageView myImage= (ImageView) findViewById(R.id.ImageSuccess);
if(userVlue.equals("SCHOOL")){
myImage.setImageResource(R.drawable.image1);
}
else if(userVlue.equals("CAR")){
myImage.setImageResource(R.drawable.image2);
}
else if(userVlue.equals("TOY")){
myImage.setImageResource(R.drawable.image3);
}
One of myImage or userVlue is not set properly and probably is null.
Debug and share logs. Your partcular activity is getting distroyed probably because of nullpointexception hence returning to main activity in backtrack.
I tried with a sample app and your logic is working perfectly.
You are handling user action on some UI element, when you do findViewById, cotext is that UI element, so this method searches ImageSuccess in children of it. Try giving page layout as rootlayout and do rootlayout.findViewById("ImageSuccess");
I found the solution finally, the black screen appeared because the images were only in the drawable file, so I needed to add the images in all drawbridge folders such as drawable-ldp, drawable-ldpi etc...., so that the app can work in different phone sizes.
I'm studying mandarin and want to change the language of my Android smartphone (Sony Xperia) between english/mandarin (or english/mandarin/portuguese/spanish) faster than using the default system settings. The way it is, I have to enter settings, scroll to the middle of it (which is slower than if it was on the beginning or end of the list), click Language & input, click language, have to scroll all the way down to 中文 (it should already be at the top, among the "recently used languages", but only my native language is always there), click 中文 and finally click ok.
I would like to reduce those 6+ clicks to a single button in the quick settings area (there is space for 4 more icons): when the phone is in a language, a tap on the icon would change to the next language, holding the icon would open a menu to add/remove languages/change order/etc.
I'm new to Android development, so I don't know if it's possible for an app to change the system language (need root privileges? I want it for myself, even if I won't be allowed to share it on Google Play, for instance). I've seen many answers on how to change an app language, that's not what I'm looking for. I also found many apps in Google Play, all of them promising to "quick toggle system language" etc, but none of them worked on my device. The closest I got was this, but looks like a dead thread.
So, is it possible? If so, where is the documentation?
I think this is what you might looking for!!!
If you would like to have your own application you can try this app i just created for you here!!!
Language Picker Widget
The Java Code
public class MainActivity extends Activity {
private Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.add_button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//in the line below it tells it to go to the language selection list
Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
startActivity(intent);
MainActivity.this.finish();
}
});
}
}
The Layout File
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change System Language"
android:id="#+id/add_button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
You can start a project in eclipse, use the codes above for the activity and the layout and then test it on the emulator
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.
With one button i'm disabling three other button's with button.setEnabled(false).
That works fine.
When this button is pressed again, the tree button's will be enabled with button.setEnabled(true).
They are still doing what they shoud and are fine responding to the onClickListener.
But since the enabling they do not visible respond when they get pressed.
How do i reactivate them right?
(i already searcht in google but didn't find anything).
private void startSleeping()
{
editorState.putBoolean("SLEEPING", true);
editorState.commit();
buttonDrink.setEnabled(false);
buttonEat.setEnabled(false);
buttonWash.setEnabled(false);
buttonDrink.setBackgroundColor(getResources().getColor(R.color.darkgray));
buttonEat.setBackgroundColor(getResources().getColor(R.color.darkgray));
buttonWash.setBackgroundColor(getResources().getColor(R.color.darkgray));
buttonSleep.setBackgroundColor(getResources().getColor(R.color.orange));
buttonWash.setTextColor(getResources().getColor(R.color.lightgray));
buttonDrink.setTextColor(getResources().getColor(R.color.lightgray));
buttonEat.setTextColor(getResources().getColor(R.color.lightgray));
buttonSleep.setTextColor(getResources().getColor(color.black));
}
private void stopSleeping()
{
editorState.putBoolean("SLEEPING", false);
editorState.commit();
buttonDrink.setEnabled(true);
buttonEat.setEnabled(true);
buttonWash.setEnabled(true);
buttonDrink.setBackgroundColor(getResources().getColor(R.color.transparent));
buttonEat.setBackgroundColor(getResources().getColor(R.color.transparent));
buttonWash.setBackgroundColor(getResources().getColor(R.color.transparent));
buttonSleep.setBackgroundColor(getResources().getColor(R.color.transparent));
buttonWash.setTextColor(getResources().getColor(R.color.white));
buttonDrink.setTextColor(getResources().getColor(R.color.white));
buttonEat.setTextColor(getResources().getColor(R.color.white));
buttonSleep.setTextColor(getResources().getColor(R.color.white));
}
<Button
android:id="#+id/buttonEat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingBottom="#dimen/padding_size"
android:paddingTop="#dimen/padding_size"
android:text="#string/button_eat"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/text_size" />
This is because you are setting the background resource as transparent instead of what you applied in the layout as the background drawable to those buttons. Re-apply those background drawables and you'll get the touch feedback again. That should solve your problem.
On a side note for future implementations you can directly provide the enabled/disabled background resource in the drawable's list-selector itself. use state_enabled = true/false. This eliminates the need of doing all of that in the code.
I am working on a Android Project in which I need to show a Button or ImageView on header of my activity(Screen). Below is my XML layout of my activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_margin="2px"
android:orientation="vertical"
android:padding="2px" >
<LinearLayout
android:id="#+id/tabBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:padding="0px"
android:src="#drawable/button" />
</LinearLayout>
</LinearLayout>
With the above layout, I can see my black button image just below the Proximity title. Is it possible to show my button image to left of Proximity instead of getting shown one line below Proximity?
Or
Is there any way, I can make the image which is left to Proximity title clickable? if I can do that, then I don't need to show Black Button image at the top.
That image is coming from AndroidManifest.xml file. I am not sure how to make that clickable.
With the above layout, I can see my black button image just below the
Proximity title. Is it possible to show my button image to left of
Proximity instead of getting shown one line below Proximity?
Since Proximity is in titlebar you need to create your own custom titlebar to be able to place button to titlebar. Here is example how to achieve it.
Also try to think an usage of ActionBar.
Try this
Button b=new Button(context);
View v = findViewById (android.R.id.title); // Getting the title bar view
v.addView(b); // setting Button
v.setClickable(true);
v.setOnClickListener(new OnClickListener() {
#Override public void onClick(View v) {
Toast.makeText(context, "You have clicked on Title", Toast.LENGTH_SHORT).show();
}
});
How ever I'll suggest you to use ActionBar
Note: I haven't tried that. Let me know if it work for you