Android app always show app name in toolbar - java

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

Related

Dismiss a child view without it executing the parent view OnCreate function

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()

How to make title background transparent on android app

There is an issue in the follow Android App where guidance is greatly appreciated. This application is to support a Renesas RX130 microcontroller and Texas Instrument CC2650 Bluetooth Low Energy hardware demonstration design. In the initial device scanning page the tile has a bright red background as shown below.
The tool bar has a Purple to Red gradient background.
Question: How can the Red Tile background be made transparent?
The application has two activities. Below are excepts from the AndroidManifest.xml file
<activity android:name="capsense.application.rx130_cc2650.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="capsense.application.rx130_cc2650.DeviceControlActivity"/>
<service android:name="capsense.application.rx130_cc2650.BLE_Service" android:enabled="true" />
Code from activity_main.xml, listitem.xml, toolbar.xml and MainActivity.java generated the first activity. Relevant sections of code is from the files are below.
Excepts from activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Excepts from toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher_background_rx130_cc2650"
app:popupTheme="#style/CustomerPopUpMenuStyle"
app:theme="#style/CustomerToolbarStyle"
app:titleTextColor="#android:color/white">
</android.support.v7.widget.Toolbar>
Excepts from MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(capsense.application.rx130_cc2650.R.layout.activity_main);
mScanning = false;
//Get User Interface Elements
Toolbar toolbar = findViewById(capsense.application.rx130_cc2650.R.id.toolbar);
toolbar.setTitle(R.string.app_label);
setSupportActionBar(toolbar);
The complete project is available on github Android_Mobile_App_RX130_CC2650
References:
Set transparent background of an imageview on Android
Toolbar with Gradient Background set title background transparent
There is a conflict in color from multiple source to background.
Don't use theme unless if needed, as
theme influence all the views and layouts inside the toolbar
style influence only the toolbar and does not interfere with views and layouts inside toolbar
Please try below options, one of which might work for you,
Option 1 (preferred): update CustomerToolbarStyle code as below
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#drawable/ic_launcher_background_rx130_cc2650</item>
<item name="android:title">#color/colorforeground</item>
</style>
update toolbar.xml code as below
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="#style/CustomerPopUpMenuStyle"
style= "#style/CustomerToolbarStyle"
app:titleTextColor="#android:color/white"/>
Option 2: set transparent background in CustomerToolbarStyle
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<!-- set background color to transperant -->
<item name="android:background">#00000000</item>
<item name="android:title">#color/colorforeground</item>
</style>
Option 3: remove android:background from the CustomerToolbarStyle
<style name="CustomerToolbarStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:title">#color/colorforeground</item>
</style>
Option 4: remove app:theme="#style/CustomerToolbarStyle" from toolbar.xml
If above options not working, please check below links
Change Toolbar background color programmatically does not change Toolbar Title Background color
Text background issue on Toolbar

AutocompleteTextView click listener called twice

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.

BottomAppBar raises while using soft keyboard

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"

Custom Facebook Share-Button, Android App

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.

Categories