I'm trying to hide BottomAppBar behind keyboard but when I change focus to another EditText the part of BottomAppBar start to appear like in photo . Also I have already tried change windowSoftInputMode but I really need adjustPan.
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:backgroundTint="#color/colorAccent"
app:fabCradleMargin="#dimen/fab_margin"
app:fabCradleRoundedCornerRadius="#dimen/fab_corner_radius"
app:hideOnScroll="false"
app:layout_scrollFlags="scroll|enterAlways"
android:transitionName="bottom_appbar"
style="#style/Widget.MaterialComponents.BottomAppBar" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/bottom_fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="true"
app:tint="#color/colorPrimary"
android:tint="#color/colorPrimary"
app:backgroundTint="#color/floatButtonColor"
app:rippleColor="#color/colorAccent"
app:layout_anchor="#id/bottom_appbar"/>
try adding this to your <activity> tag in the manifest
android:windowSoftInputMode="adjustPan|stateHidden"
Related
I am making a chat app and I want to add a feature like telegram to copy links ,phone numbers and etc.. from long clicking on an auto link.I used this library to add long click listeners on a auto link.I implemented it successfully.But when I do this, i want to show a Lottie animation in the start like this but on long click of a link.
I tried many answer but I get an exception.I already made the layout for custom snakbar.It is given below
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="56dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="#dimen/_3sdp"
android:backgroundTint="#color/snakbar_background"
app:cardCornerRadius="#dimen/_4sdp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/lottieSnakbar"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginEnd="#dimen/_10sdp"
app:lottie_rawRes="#drawable/copy"
app:lottie_autoPlay="true"
app:lottie_loop="false"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Text copied to clipboard"
android:gravity="center_vertical"
android:theme="?snackbarTextViewStyle"
tools:ignore="HardcodedText" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Now how can I achieve this?
You can use an interface in the adapter. And receive and show snakbar from activity
You could use localBroadcast and broadcast a local signal from the adapter and let the other Activity(probably receiver) handle snakbar.
AdapterClass{
LocalBroadcastManager localBroadcastManager = null;
void sendB(parms){
if(localBroadcastManager != null){
localBroadcastManager.sendBroadcast(Intent("NOTIFICATION_RECEIVER"))
}
onCreateViewHolder(){
localBroadcastManager = LocalBroadcastManager.getInstance(applicationContext)
}
onBindViewHolder(){
if(someCondition){
sendB(parms);
}
}
then receive it from an activity then call snakBar
I've this layout:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/input_birthdate"
style="#style/ExposedDropDownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/birthdate">
<AutoCompleteTextView
android:id="#+id/autocomplete_birthdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false" />
</com.google.android.material.textfield.TextInputLayout>
With this style:
<!-- ExposedDropdownMenu -->
<style name="ExposedDropDownMenu" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<item name="boxStrokeColor">#color/text_input_layout_outlined_box_stroke</item>
<item name="hintTextColor">#color/green_2</item>
</style>
I've tried to set a click listener on the autocomplete text view:
autoComplete.setOnClickListener(view -> {
// This is called twice when i click the autocomplete textview
});
The listener is called twice...why? How can i solve this?
EDIT: removing the style, the first click (gaining the focus) is ignored, than the second click is called correctly once, but I lose the "ripple" background effect anyway.
You can try the setOnTouchListener instead, it's called just once and keeps the ripple as well.
autocomplete_birthdate.setOnTouchListener { view, motionEvent ->
if (motionEvent.action == ACTION_UP) {
// Some code
}
return false
}
You should try the below example.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Click Event"
app:boxStrokeColor="#color/til_selector"
app:boxStrokeErrorColor="#color/colorRed_700"
app:boxStrokeWidth="1dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etClickEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
**android:focusableInTouchMode="false"** />
</com.google.android.material.textfield.TextInputLayout>
Now set Programmatically
etClickEvent.inputType = 0
etClickEvent.setOnClickListener{
//PUT YOUR OWN
}
This is working fine for me.
I want to show a specific text in my app toolbar but it also always shows the name of the app too. How can I get rid of the app name and only the text of the TextView?
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true" >
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:fitsSystemWindows="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="The title I want to show"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Add label to activity declaration in AndroidManifest.xml file.
<activity
....
android:label="Name of Your Screen"
....
</activity>
For static activity name, set android:label="Activity Name" attribute for each activity in AndroidManifest.xml
...
<activity
...
android:label="Activity Name">
...
</activity>
...
For dynamic activity name, you can use the following:
getActionBar().setTitle("Activity Name");
To provide compatibility across all the android versions, use:
getSupportActionBar().setTitle("Activity Name");
But if you want to completely get rid of the title bar, you can extend Activity instead of AppCompatActivity or you can hide the action bar:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
you just write this line in your activity getSupportActionBar().setDisplayShowTitleEnabled(false);
and it will set the visibility of the app name to invisible
Use
<activity
android:label="blah-blah" />
to set it in the manifest file.
Or in the code toolbar.setTitle("blah-blah");
If you set your Toolbar like ActionBar then you can call actionBar.setTitle("blah-blah");.
From the modification of the accepted answer, this actually resolved my issue.
All you need to do is to leave the "label name" text as blank in your manifest as example below
...
<activity
...
android:label=" ">
...
</activity>
...
this will actually enable only your textview text in your toolbar widget to show, it works very fine for me
So I want to implement a custom Facebook share button into my Android app, but thus far I've only managed to use the native one, which I imported into my .xml file and made use of in my Java activity for that specific page.
My code looks like this (in .xml);
<com.facebook.share.widget.ShareButton
android:id="#+id/share_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Share"
android:layout_centerHorizontal="true"/>
And in my .java, outside onCreate();
private ShareButton shareButton;
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.setContentTitle("MyTitle")
.build();
Inside onCreate();
shareButton = (ShareButton)findViewById(R.id.share_btn);
shareButton.setShareContent(content);
How would I go about making use of a custom button that I've imported into XML? Using .setShareContent obviously doesn't work if it's not an instance of ShareButton. Thanks in advance!
I have found a solution. It's clear that facebook share will work on its own button click event. So you will have to explicitly call the View.performclick() method.
Here is how i have done this:
In my layout
<com.facebook.share.widget.ShareButton
android:id="#+id/share_btn_fb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:contentDescription="#string/share" />
<LinearLayout
android:id="#+id/share_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/google_share" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/share_google"
android:textColor="#color/green_color"
android:layout_marginLeft="5dp"
android:textSize="18sp" />
</LinearLayout>
Inside activity get refrences of these views.
ShareButton shareButton = (ShareButton) layout.findViewById(R.id.share_btn_fb);
LinearLayout shareFB = (LinearLayout) layout.findViewById(R.id.share_btn);
LinearLayout shareGoogle = (LinearLayout) layout.findViewById(R.id.share_google);
shareGoogle.setOnClickListener(this);
shareFB.setOnClickListener(this);
Inside onClick()
case R.id.share_btn :
shareButton.performClick();
break;
case R.id.share_btn_fb :
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle("Content title")
.setContentDescription("App descr")
.setContentUrl(Uri.parse("some url"))
.build();
shareButton.setShareContent(content);
break;
Basically shareButton.performClick(); is doing the trick.
i was doing small android application , i added blank xml file but it was showing some error although i did not add any code and still it was showing error so i cleaned project but now after cleaning for my activity when i write
setContentView(R.layout.reminder_edit);
its giving errors like this R cannot be resolved to a variable ,
for another activity named ReminderListaActivity i tried this
setContentView(R.layout.reminder_edit)
error was for xml file not for "R " error was :reminder_edit cannot be resolved or is not a field .
xml file is in layout and its showing like never used file so how do i solve this issue , can someone help me with it pleae
EDIT code added
reminder_edit.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="#string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/body"
/>
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="5"
android:scrollbars="vertical"
android:gravity="top" />
<TextView
android:text="#string/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/reminder_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Reminder_Time"
/>
<TextView
android:text="#string/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/remindertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/remindertime"
/>
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
java File
public class ReminderEditActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_edit);
}
}
Fix the errors in XML so the resource compiler can generate R.java for you.
Remove Import android.R; from imports in your activity class
In order to accesst "R.layout.edit_reminder" xml file you must import your "R" file which is found under the "gen" folder. This file is automatically generated, so you can go ahead and delete it and it will be generated again. Now, if you have any xml errores whatsoever the R file won't be generated, that's a sign that you have to look to your xml to find the problem.
In regards to the import, you'll find them on your Activity Class, at the very top right after the package declaration.
Make sure that the R you are importing is:
yourpackage.R;
rather tahn
android.R;
When writing code quickly at times android.R gets imported and you don't even notice. That's the first thing I always check, it's happened to me a couple of times already.
Next thing I would suggest doing is looking to see your console and problems view (if these are not set in your perspective, then go to Window>Show View>Other and select the appropriate ones).
Look for something along the lines of Error with xml file aborting build. Look for what xml file it is talking about, and then look for errors in it.