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.
Related
I have the following in my AndroidManifest.xml file:
<activity
android:name=".PickemAllPicksResultsActivity"
android:label="#string/title_activity_backActionBar"
android:parentActivityName=".PoolDetailsActivity"
android:screenOrientation="portrait" />
The above places a back button/arrow (in the action bar) in my child view in order to navigate back to the parent view.
I have the following layout for the child view:
<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=".PickemAllPicksResultsActivity" >
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weekly" />
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Overall" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tabLayout"
android:layout_centerHorizontal="true" />
</RelativeLayout>
When i click on the back button in the action bar the app crashes because the parent view is executing the onCreate which is calling a Firebase function:
// Get the Pool Info
poolReference = mFirebaseDatabase.getReference("PICKEMPOOLS").child(poolID);
and poolID is null.
Question, why does this back button trigger the OnCreate function, but if I press the back button on the Android Navigation is just dismisses the screen and goes to the previous view?
From my understanding, if you want to get back click the event implemented below will give you a callback when back pressed.
// This callback will only be called when MyFragment is at least Started.
OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) {
#Override
public void handleOnBackPressed() {
// Handle the back button event
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(this, callback);
// The callback can be enabled or disabled here or in handleOnBackPressed()
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"
I'd like my Spinner dropdown items to fill the entire screen width even tho my 'title' does not. Problem is the dropdown menu width seems to be limited the Spinner's title width.
My goal is to make it fill the entire screen width, with no spacing left or right, right below the action bar. A similar one to what I'm trying to do would be Instagram's menu to change profile.
I looked to similar questions but didn't find a solution that worked here. Also tried to create a custom adapter and making sure its views had match_parent attribute on their width. But didn't work either.
main.java (only relevant part of the code for legibility)
mMyListsSpinner = (Spinner) findViewById(R.id.spinner_mylists);
ArrayAdapter<String> snipperAdapter = new ArrayAdapter<String>(
FamilistActivity.this, R.layout.layout_spinner_title, dummyLists);
snipperAdapter.setDropDownViewResource(R.layout.layout_spinner_dropdown);
mMyListsSpinner.setAdapter(snipperAdapter);
mMyListsSpinner.setOnItemSelectedListener(this);
layout_spinner_title.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/color_white_bright"
android:maxLines="1"
style="#style/OverflowMenu"
android:text="this is my list"/>
layout_spinner_dropdown.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_spinner_dropdown"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_actionbar_height"
android:maxLines="1"
android:textSize="18sp"
android:textColor="#color/color_green_dark"
android:background="#color/color_white_bright"/>
styles.xml (only the relevant part)
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">16dp</item>
<item name="android:dropDownHorizontalOffset">-15dp</item>
</style>
my toolbar:
toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bar_appbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_actionbar_height"
app:layout_collapseMode="pin"
android:background="#color/color_green_bright">
<Spinner
android:id="#+id/spinner_mylists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:dropDownWidth="match_parent"
style="#style/OverflowMenu"/>
By looking into AppCompatSpinner.java and running the debugger I saw in this line in computeContentWidth()
else if (mDropDownWidth == MATCH_PARENT) {
setContentWidth(spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight);
}
that SpinnerPaddingRight has a value that is not 0. I solved it by setting
android:paddingEnd="0dp"
in the Spinner view.
I have a TextInputLayout. I try to apply custom hintTextAppearance style
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/wizard_horizontal_margin"
android:paddingRight="#dimen/wizard_horizontal_margin"
android:paddingTop="#dimen/wizard_vertical_margin"
android:paddingBottom="#dimen/wizard_vertical_margin">
<TextView
android:paddingBottom="#dimen/wizard_vertical_margin"
android:text="What's your email address?"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/wizardTextViewColor"
android:textSize="18sp"
android:id="#+id/text_view" />
<android.support.design.widget.TextInputLayout
app:hintTextAppearance="#style/WizardTextInputLayout"
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email address"
android:id="#+id/email_edit_text" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
I try to make the text bold by applying the following custom style.
<style name="WizardTextInputLayout" parent="TextAppearance.Design.Hint">
<item name="android:textStyle">bold</item>
</style>
However, it looks no different before & after applying the custom style.
Before custom hintTextAppearance style
After custom hintTextAppearance style
I can confirm the styling works. As, if I add android:textSize attribute in WizardTextInputLayout style, I can see there is change on floating label text size.
But, why making the floating label text bold doesn't work? Anything I can try out to make the floating label text bold?
Update
As setting a custom typeface for the textinputLayout will affect the hint text appearance and style that is mananged by it, you can use the setHintTextAppearance(int resId) method of TextInputLayout, with providing a custom text style xml, to overcome the issue.
Original Answer
You can create a custom class extending the TextInputLayout class and overriding the setTypeFace() method :
#Override
public void setTypeface(#Nullable Typeface typeface) {
setTypeface(Your_Bold_typeface);
}
where you should set a typeface created from the bold version of your desired font.
I create a custom facebook login button, but the icon on the button is not showing corretly. can you help me please
Login XML:
<Button
android:id="#+id/login_button"
style="#style/ParseLoginUI.Button.ThirdPartyLogin"
android:layout_marginTop="#dimen/com_parse_ui_small_vertical_spacing"
android:background="#drawable/com_parse_ui_facebook_login_button_background_selector"
android:drawableLeft="#drawable/com_parse_ui_facebook_login_logo"
android:text="#string/com_parse_ui_facebook_login_button_label"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
Style:
<style name="ParseLoginUI.Button.ThirdPartyLogin" parent="ParseLoginUI.Button">
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">24dp</item>
</style>
<style name="ParseLoginUI.Button" parent="#android:style/Widget.Button">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">48dp</item>
<item name="android:background">#drawable/com_parse_ui_parse_login_button_background_selector</item>
<item name="android:textColor">#color/com_parse_ui_parse_login_display_text</item>
<item name="android:textSize">18sp</item>
</style>
Code:
loginButton = (Button)findViewById(R.id.login_button);
//loginButton.setBackgroundResource(R.drawable.com_parse_ui_facebook_login_logo); //DONT WORK
//loginButton.setCompoundDrawablesWithIntrinsicBounds(0, 0,0,0); //DONT WORK
I want my button to look like this
http://i.stack.imgur.com/xKxX3.png
originally its from the Parse sample
This is how its showing
No need to create extra drawable . Just call
<com.facebook.widget.LoginButton
android:id="#+id/authButtonFb"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You will also need to add this to the Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fb="http://schemas.android.com/apk/res-auto"
For Details Login with Facebook And customize-android-facebook-login-button
If you use Android studio Then call this in your build.gradle
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
I hope it will helps you .
instead of button use default facebook button(Please add facebook jar).it will give you same output as you want.
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
Using facebook-android-sdk:3.19.0 dependency:
<com.facebook.widget.LoginButton
android:id="#+id/button_facebook_login"
android:drawableStart="#drawable/com_facebook_inverse_icon"
android:drawableLeft="#drawable/com_facebook_inverse_icon"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
If you are using facebook-android-sdk:4.20.0, the drawable icon is named com_facebook_button_login_logo