i want to use Navigation Drawer in my app. according google documentation here, i write my UI code like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
MAIN LAYOUT IS HERE
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
this is like google's own example but it gives me an error in layout preview:
Exception raised during rendering: DrawerLayout must be measured with MeasureSpec.EXACTLY.
i searched a lot about it, some people says that you have to put explicit values for android:layout_width and android:layout_height. when i do this everything is going to be OK but i dont want to put explicit values! because i dont know every device width and height... how i can fix that? whats the solution?
i already put android-support-v4.jar file in lib folder. i think its the latest version.
just right click on project >> select android tool >> select add support library .
this should work , just do same steps !
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'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.
Firstly, I have searched and seen similar questions on Stackoverflow however I'm building outside Android studio or Eclipse so mine is a bit different and I'm looking for a solution or alternative if possible.
I am building a plugin that sends messages between Java and Javascript using Cordova.
I have 3 lines to resolve:
setContentView(R.layout.main);
mPreview = (CameraSourcePreview) findViewById(R.id.preview);
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
Specifically just the setContentView(R.layout.main), findViewById(R.id.preview) and findViewById(R.id.faceOverlay). The layout file is in ../../../res/layout/main.xml and ../../../res/layout-land/main.xml.
All I want is a way to access, I do not have a R.java file and I'm not very experienced with Java unlike Javascript.
Is there a way to point to those files please, thanks.
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/topLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<com.cordovaplugincamerapreview
android:id="#+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cordovaplugincamerapreview
android:id="#+id/faceOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.cordovaplugincamerapreview>
</LinearLayout>
I am trying to use a CoordinatorLayout to anchor a view to another one and it is working almost perfectly. The problem is that when i switch to another fragment, open the keyboard, then switch back, the anchored view gets messed up. Sometimes after a couple seconds it (seemingly) randomly snaps back into place. Here is a gif to demonstrate what I am talking about.
As you can see, the FloatingActionButton is not aligned when I return to the fragment, but after a while it snaps back into place. What could cause this issue?
Fragment XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:id="#+id/coordinatorLayout_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
<!-- Other views -->
<!-- Bottom sheet -->
<include
android:id="#+id/bottom_sheet"
layout="#layout/bottom_sheet_primes"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/fab_margin"
android:src="#drawable/ic_play_arrow_white_24dp"
app:backgroundTint="#color/accent"
app:layout_anchor="#id/bottom_sheet"
app:layout_anchorGravity="top|end"/>
</android.support.design.widget.CoordinatorLayout>
The solution to this is to use android:windowSoftInputMode="adjustPan" attribute in your activity tag of the activity in question in the AndroidManifest.xml file.
I have a layout which I want to be scrollable when content is overflowing the screen.
I have the following layout xml set up.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/ScrlView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:isScrollContainer="false"
android:id="#+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/backrepeat">
<!-- Include Header -->
<include layout="#layout/main_header"/>
<!-- Include dashboard -->
<include layout="#layout/dashboard"/>
</LinearLayout>
</ScrollView>
A dashboard is a collection of icons serving as a menu. Example: click me
Unfortunately, the second include (dashboard) shows 'broken' now. See screen:
Click here
As you can see it doesn't look like it's suposed to. When I delete the scrollview, everything is fine.
What I want is for my dashboard to still look good, but be scrollable if needed.
I tried several setups but all give the same result. What am I doing wrong?
Any help would be appreciated :)
Remove the android:isScrollContainer="false", and add android:fillViewport="true" to scrollView