Create facebook like menu - java

I want to open a menu of options similar to that of Facebook. I did a search but I did not find anything ...

You will probably be needing to use Bottom Sheets for that :
I - Make a bottomsheet.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:padding="16dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<!-- add your content here -->
</LinearLayout>
II- now in your main activity implement it in a way it is a direct child of a CoordinatorLayout
<include layout="#layout/bottomsheet" />
III- For the JAVA code use the following:
inearLayout bottomSheetViewgroup = (LinearLayout) findViewById(R.id.bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup);
To control your bottom sheet (hiding, expanding, dragging, collapsing):
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
PS- you can handle this by :
STATE_EXPANDED: To completely expand the bottom sheet.
STATE_HIDE: To completely hide the bottom sheet.
STATE_COLLAPSED: To set the bottom sheet height with the value set on the peekHeight attribute.

Related

Where in android studio can I change the appbar text?

I'd like to change and align the text, and possibly add features on appbar in the screen above.
However, it'd be best if I could find and modify the text and align it IF I don't intend to add features.
But then I wasn't able to find where in android studio I could change the text.
I thought I could find one in the main activity xml file but I couldn't. I looked up at themes.xml and AndroidManifest.xml but couldn't find a clue.
Here is first 13 lines of my main activity xml file just in case.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<SurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_height="480dp"
app:layout_constraintTop_toTopOf="parent"/>
So, to cut it short, where in android studio can I change the text in toolbar? or appbar? above in the screen without having to create toolbar.xml? (+ align the text in the center and change text color)
Apparantly you don't have toolbar implemented in your xml layout
In Your style file make sure you set it to noActionBar
<style name="Theme.ChatApp" parent="Theme.AppCompat.Light.NoActionBar">
Then you have to add your own toolbar
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toolbar"
android:background="#color/white"
app:navigationIcon="#drawable/ic_baseline_dashboard_24"
app:title="here you can put your title"/>
In your activity reference your toolbar in your onCreate
setSupportActionBar(findViewById(R.id.toolbar)
PS : If you are using MaterialToolbar please consider add this material library
implementation 'com.google.android.material:material:1.1.0'

Android Studio - How to programmatically add layout_below param to CardViews inside a PercentRelativeLayout

I am here because I am trying to set programmatically the layout_below parameter of some cardViews without success.
These cardViews are located inside a PercentRelativeLayout (I do not know if it is relevant but these cardviews have been added programmatically too).
I show you the code to make it clear.
...
<android.support.percent.PercentRelativeLayout
android:id="#+id/prl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv0"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv1"
// here I would like to add android:layout_below="#+id/cv0"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv2"
// here I would like to add android:layout_below="#+id/cv1"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
</android.support.percent.PercentRelativeLayout>
...
I tried to do something like this in my Java code but without success.
PercentRelativeLayout prl = (PercentRelativeLayout) view.findViewById(R.id.prl);
CardView cv = (CardView) LayoutInflater.from(getActivity()).inflate(R.layout.cv_block, prl, false);
cv.setId(currentId++);
prl.addView(cv);
cv = (CardView) LayoutInflater.from(getActivity()).inflate(R.layout.cv_block, prl, false);
cv.setId(currentId++);
RelativeLayout.LayoutParams cv_lp = (RelativeLayout.LayoutParams) cv.getLayoutParams();
cv_lp.addRule(RelativeLayout.BELOW,currentId-2);
/* I have also tried to call cv.requestLayout() but nothing changed */
prl.addView(cv);
As you can see, I am trying to generate cardviews and insert them one below the other.
Thanks in advance for your help.
PercentRelativeLayout is depreciated, so you are encouraged to use other type of layout.
This class was deprecated in API level 26.1.0.
consider using ConstraintLayout and associated layouts instead. The following shows how to replicate the functionality of percentage layouts with a ConstraintLayout. The Guidelines are used to define each percentage break point, and then a Button view is stretched to fill the gap:
ConstraintLayout gives lots of opportunities.
More about PercentRelativeLayout deprecation here.
More about ConstraintLayout and how to use it here or video tutorial.

Android: Default layout for listitem containing title and subtitle

I have made a listitem, containing a title and a subtitle. Looking to the result, I think it doesn't look really professional. So that's why I'm asking.
The listitem I'm looking for is pretty common (it's used in a lot of apps i.e. Android's default settings menu and it's also shown when you add a listview in the graphical layout editor tab in eclipse).
So my question is: Where can I find a default layout for a listitem with a title and a subtitle?
Resource id is android.R.layout.simple_list_item_2
Upper text line has id android.R.id.text1 and lower one - android.R.id.text2
Layout is located in the <ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layout folder
OR
You can use TwoLineListItem from the default Android controls list(it is located under "Advanced" tab in Eclipse Layout Editor)
OR
You can build your own layout with anything you like(for example LinearLayout with orientation="vertical" and two TextEdits added
So The Best Way Is:- I took out the simple list item 2 and made an layout in my project and with little editing it took the same layout as you may give in android.R.simple_list_item_2
So the code is:-
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">
<TextView android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView android:id="#id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text1"
android:layout_alignStart="#+id/text1"
android:layout_alignLeft="#+id/text1"
android:textAppearance="?attr/textAppearanceListItemSmall" />

How to put chart in ScrollViewer?

Consider a LinearLayout with some UI items and a TChart. If I put this layout inside a ScrollViewer I would expect scrolling behavior. However, it seems that the chart auto-sizes itself to fit in the available space.
How can I make my layout scrollable when adding a chart to it?
You should have you root tag as scrollview like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView>
<LinearLayout
android:orientation="vertical">
here will come your all UI items
</LinearLayout>
TChart
</ScrollView>
or
<?xml version="1.0" encoding="utf-8"?>
<ScrollView>
<LinearLayout
android:orientation="vertical">
here will come your all UI items
TChart
</LinearLayout>
</ScrollView>
You can also download and embbeded chart widget which is available as an external widget. and is not available as an inbuilt widget in android project.

android:animateLayoutChanges won't work in parent layout

Suppose I have a layout file structured like this:
<LinearLayout android:id="#+id/main" android:orientation="vertical" android:animateLayoutChanges="true">
<EditText>
<TextView android:id="#+id/header1">
<LinearLayout android:id="#+id/insertionPoint" android:orientation="vertical" android:animateLayoutChanges="true">
</LinearLayout>
<TextView android:id="#+id/header2">
</LinearLayout>
I want to dynamically add text fields to the Layout insertionPoint and I would like to see an animation of the elements below it (in this case, header2) sliding down.
Using android:animateLayoutChanges only animates the elements in the layout insertionPoint, so there is no animation for header2. What should I do?
Just to be more clear: what I would like to do here is something like the animations that we can see in the People app in ICS when we add more fields, like telephone numbers, to a contact.
Thank you!
API 16 added the LayoutTransition.CHANGING animation type, however it is disabled by default.
To enable:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
linearLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
Nice DevBytes video: https://www.youtube.com/watch?v=55wLsaWpQ4g

Categories

Resources