one tap to display edit text and keyboard android - android-layout

I'm creating an Android app and i need to add text on a picture.
I need to do a snapchat-like to add my text : I managed to display an editText when you click on the picture but then i have to tap again on the EditText to display the keyboard.
But I need only one click to display the EditText AND the Keyboard.
Thanks for your help.
ImageView iv = (ImageView)findViewById(R.id.imageView1);
iv.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText et=(EditText)findViewById(R.id.editText1);
et.setVisibility(View.VISIBLE);
}
});

in case someone is in the same problem, here's the answer :
ImageView iv = (ImageView)findViewById(R.id.imageView1);
iv.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
EditText et=(EditText)findViewById(R.id.editText1);
et.setVisibility(View.VISIBLE);
et.setFocusableInTouchMode(true);
imm.showSoftInput(et, 0);
}
});
And for the XML file set the EditText like this :
android:visibility="invisible"

Related

How can I change Snackbar background text color in Android Studio?

My Snackbar background displays the default background I've set on the Theme.xml. So, how do I change the background color of the SnackBar?
Any help would be much appreciated.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityNewDeltioBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = binding.viewPager;
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = binding.tabs;
tabs.setupWithViewPager(viewPager);
FloatingActionButton fab = binding.fab;
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar message = Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null);
message.show();
}
});
}
Edit:
I've also tried creating a custom style, but that didn't work as expected. It changed the color of the SnackBar sides, not the background itself...
You might have to try message.setBackgroundColor(colorYouWant).
Also, if you have a colors.xml, I would say to make sure that you're correctly naming the colors.
For more information, you could also check out this answer.

How to open a link using a CardView

What I want to do is to click on a CardView send me directly to the browser with a link already inserted as I can achieve that would greatly appreciate your help :).
Use the following code. Replace it with the id of your cardview in place of your_cardview_id
CardView cardView;
cardView = findViewById(R.id.your_cardview_id);
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
}
});

I want to make Edit text clickable so that when i click on it, it should show a text like one android studio

this is my code I want to add a text whenever I click on edit text.
`jet1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
jet1.setText("One");
}
});`
To make an editText clickable
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// do things you want
}
});

Android Custom Dialog Display

My custom dialog layout has 2 edit text fields.
<EditText
android:id="#+id/e2"
android:inputType="none"
android:longClickable="false"
android:selectAllOnFocus="true"
android:textIsSelectable="true" />
<EditText
android:id="#+id/e2"
android:inputType="none"
android:longClickable="false"
android:selectAllOnFocus="true"
android:textIsSelectable="true" />
I implement my class using OnFocusChangeListener.
My idea is when I click the text field, one custom popup dialog appears to select my pre-defined value.
It work correctly but I have a minor problem.
If I click the editext 1 => dialog apear (I select the button then it dismisses) => click editext 2 => dialig appear (I select the button then it dismisses).
However, if If I click the editext 1 => dialog appears (I select the button then it dismisses), then I click on editext 1 immediately again (even many times I try), my dialog does not show up (In expectation, it should appear whenever I click).
My Class
public class user_input extends Activity implements OnFocusChangeListener {
#Override
public void onFocusChange(View v, boolean hasFocus) {
final EditText edt = (EditText) findViewById(v.getId());
if (hasFocus) {
final Dialog dialog = new Dialog(user_input.this);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("SELECT A NUMBER: ");
dialog.show();
btn1 = (Button) dialog.findViewById(R.id.val1);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt.setText("1");
dialog.cancel();
}
});
btn2 = (Button) dialog.findViewById(R.id.val2);
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt.setText("2");
dialog.cancel();
}
});
}
}
How to show it as my expectation? Thank you very much in advanced.

How to permanently change a textView using editText from the app

I am trying to change the text of a text view to that of the inputted text from the edit text. i can do this easily with setText, yet when i exit and reenter the app, the textView has reset to its original value. I want to permanently change the textview value so when i exit and reenter the app, the textview is the same value i entered in the EditText.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button clicker = (Button) findViewById(R.id.button);
final TextView text = (TextView) findViewById(R.id.textView2);
final EditText input = (EditText) findViewById(R.id.input);
final Editable str = (Editable) input.getText();
clicker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
text.setText(str.toString());
}} );
The android framework automatically saves the state of certain views when your activity is destroyed. Unfortunately, TextView is not one of those views (but EditText is).
See this question:
Restoring state of TextView after screen rotation?
You should learn more about the activity lifecycle, specifically about recreating an activity:
http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Resources