I am using Android Studio 1.5.1 for the first time. Problem is that when I change the value of a TextView control either through its XML code or from its Properties window, it is not changed on Preview (Design View). However, when I test the application, it displays the updated value.
Here is screenshot...
Value of TextView is changed in Properties window, but not updated on Layout Preview
I have tried several things, like Clean, Rebuild, Invalidate Cache/Restart. My SDK and Android Studio is also updated...
EDIT
28-Feb-16
I have got a strange solution for this problem. Actually, I was trying to render my activity in Layout Design for API Level 23. I first opened activity_main.xml file and comment out the following xml code: -
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
and also comment out this code: -
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
And then opened MainActivity.java file and comment out the following code: -
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
It solved my both problems. Now Design View of Layout file (content_main.xml) is updating as I change it in xml code. And also Design View is rendering successfully for API Level 23. Previously, it was creating Rendering Problems for API Level 23. As far as the rendering problems, I am understanding it somehow. But why Design View of Layout File is now updating?
What you can do is use preview for xml changes. android studio provides preview screen for view xml changes. it shows changes instantly so you can also view while doing changes and there is also refresh button there in case if you are not able to see changes by any technical error just press refresh button which will refresh the xml design.
Related
In my project I'm using this material drawer lib of version 5.0.0 and this QR code reader lib of version 2.0.1. XML layout has the following structure:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="#layout/include_qr_reader" />
<Toolbar
android:id="#+id/toolbar"
...
/>
...
</FrameLayout>
Here #layout/include_qr_reader is just a view:
<com.dlazaro66.qrcodereaderview.QRCodeReaderView
android:layout_width="match_parent"
android:layout_height="match_parent" />
In my activity class first I'm checking camera permissions and if granted I just call viewStub.inflate(). In result my drawer gets cropped as seen in the image below:
After the view gets updated (some button clicked) the drawer gets back to normal.
And also LayoutInspector says all ok:
If you need more info on this case just let me know in the comments section.
Question
Why does my DrawerLayout gets cropped at the bottom when camera is active?
I've already tried:
Changing layout params of drawer in code after .inflate()
Changing layout params of qrreaderview in code after .inflate()
Calling .requestLayout() and .invalidate() from QRCodeReaderView, DrawerLayout and Activity.getWindow().getDecorView()
Calling .requestLayout() and .invalidate() of those views in new Handler().post(() -> ...)
viewStub.inflate().post(() -> drawer.getDrawerLayout().invalidate())
I'm attempting to implement something similar to what you see in the Android Google Contacts app. You have a large toolbar with content underneath and when you scroll to view the content, the toolbar shrinks and the content in the toolbar shifts, fades and shrinks to fit into a standard size toolbar.
I'm using Xamarin Forms and Visual Studio 2017. My MainActivity.cs is inheriting FormsAppCompatActivity and I've implemented a standard Resource.Layout.Toolbar.
ToolbarResource = Resource.Layout.Toolbar;
The toolbar is styled so the background is transparent however.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
I cannot figure out how to get the ScrollView (or any other element) to sit underneath the toolbar. I have seen a few other posts relating to this but nothing using Xamarin Forms.
Is this possible to sit content underneath the toolbar? If so, how do I do it?
use collapsingtoolbar of material design
I am using a floating action button(FAB) in my application to show Dialogs, everything is worked just fine when I tested my app in Xperia Z with Lopllipop 5.1.1.
However, the problem is when tested my app in ASUS Zenfone 6 with KitKat 4.4.2 and in Xperia C with Jelly Bean 4.2.2, the FAB loaded perfectly but the FAB does not show the Dialogs, seems like it does not responds when I touched it.
For the record, my min sdk version is 16.
What i want to ask is why this is happening? Is there anything wrong with my code, or maybe with the android version or API level?
Please take a look at my code. Here the XML code:
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_account"
android:visibility="invisible"
android:clickable="true"/>
and here how I declare and set the listener for the FAB:
FloatingActionButton fab;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
...
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showDialog();
}
});
...
}
The thing that made me confused is how it is worked in Xperia Z but it does not worked in ASUS Zenfone 6?
The problem in here is that I declared the FAB before the declaration of listView. Somehow by relocating the declaration of FAB after the the declaration of listView it will solved the problem.
From:
<android.support.design.widget.FloatingActionButton
...
...
.../>
<ListView
...
...
.../>
To:
<ListView
...
...
.../>
<android.support.design.widget.FloatingActionButton
...
...
.../>
Just as simple as that.
Programmatically bringing the FAB to front should also work:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.bringToFront();
fab.setOnClickListener... //etc
Just add clickable and focusable and set both to "true" in FAB (floating action button) in xml file
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:clickable="true"
android:focusable="true"
/>
This enable floating button to receive click events and make clickable
My Problem:
I have a MainActivity along with its XML file activity_main.xml , which contains a NavigationDrawer view and that view calls a header.xml file to be displayed in my drawer.
The issue is that my header file contains a button so that when I click the header it opens a site. However since upgrading my Android studio build tools to 23.0.2 the onClick() for tht button inside my MainActivity crashes the app, giving me a NullPointerException.
I figure that its crashing because the header file is a totally different file from my activity_main.xml so my MainActivity would not have direct access to views inside of the header file.
How can I get access to the button that is inside the header.xml file with and also make it clickable?
Solved:
The NullPointerException was due to the fact that the layout(Header.xml) containing my Button was not readily available for the MainActivity's xml layout, therefore findViewById would always be null because to it, the button doesn't exist. This question was solved by including the header.xml with all its contents(specifically the button) into the NavigationView of the MainActivity.xml
Like so:
<android.support.v4.widget.DrawerLayout ....>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar" />
....
</RelativeLayout>
<android.support.design.widget.NavigationView
...
<include
layout="#layout/header" />
</android.support.v4.widget.DrawerLayout>
You can set the HeaderView of your NavigationView in your activity onCreate() method and set a listener to the header view like :
yourNavigationView.addHeaderView(yourHeaderView);
yourHeaderView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Handle the click event
}
});
Hi, i´m making an app and i want to add an activity just like the image above, and i´m having difficulties extendin the action bar, i´ve seen this on google design guidelines, how do i implement this on android lollipop(my min sdk is 21 i´m not interested in backwards compatibility)
thanks in advance.
It can be done by using Collapsing Toolbars which is provided in the android design support library and here is an example for knowing for using that library.
If you don't want a CollapsingToolbar , you can use a simple Toolbar using a custom minHeight.
Inside the Toolbar you can put your views, for example TextView or TextInputLayout.
Finally use a FloatingActionButton. It is important to set the attributes
app:layout_anchorand app:layout_anchorGravity
<android.support.design.widget.CoordinatorLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="256dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarMainTheme" >
<android.support.design.widget.TextInputLayout>
<TextView>
</android.support.v7.widget.Toolbar>
<!-- your scrollable view here -->
<android.support.design.widget.FloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:borderWidth="0dp"
app:elevation="4dp"
app:pressedTranslationZ="6dp"
android:layout_marginRight="#dimen/fab_margin_card"
android:src="#drawable/ic_youricon"
app:layout_anchor="#id/toolbar_main"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
You just need to add an EditText and several TextViews (or wrap the EditText in a TextInputLayout) into the Toolbar in your layout xml.
https://gist.github.com/chris95x8/53214de145571d410e13