I am using BottomNavigation for my layout and after I press one button and change the page, the button looks as if I am still pressing it. It helps me if someone can give me a solution.
XML file
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
android:background="?android:attr/windowBackground"/>
The glitch:
In my Android app, I have a WebView and 6 buttons inside a ConstraintLayout. The WebView should zoom fully out on start, but it instead goes only to the width of the device.
The WebView is set up like layout_width="fill_parent" layout_height="0dp", which should be match_constraint
My current code is:
web.getSettings().setSupportZoom(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setDisplayZoomControls(false);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
WebView XML:
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:clickable="false"
app:layout_constraintBottom_toTopOf="#id/button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
</WebView>
I expect the WebView to show the full image/video, but it's still scrollable in horizontal direction, sometimes it even puts black bars below and above it.
Video demonstation: https://youtu.be/ucmLNksNGRI
I am developing an application that has a home page with a progress bar I have to represent many progress bar on slideshow, I tried ViewFlipper but its only for images. What shall I do. help.`
viewFlipper=findViewById(R.id.Vi);
b = findViewById(R.id.progressBar);
viewFlipper.addView(b); //this doesn't work
the layout
<ViewFlipper
android:id="#+id/Vi"
android:layout_width="412dp"
android:layout_height="263dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.110000014"></ViewFlipper>
This where should the slideshow should be
Create a scroll view and add the progress bar on a recycler view as item in order to show them on the scroll view on parent app
I'm creating an app with a main menu, one of these menu items will open up a PreferenceFragment. To create unity within the app I'd like the main menu to look as close to the PreferenceFragment as possible. Basically all the xml values I can use to create menu items that look similar to those in the PreferenceFragment.
Examples of values I need: text size and color (for both title and summary text) and padding values.
I could guess at it but that could take awhile and may not be accurate. There has to be a better way to do it.
Here is what I have so far:
Main Menu (the menu I want to look like the PreferenceFragment): http://i.imgur.com/O5jr14e.png
Preferences (the PreferenceFragment): http://i.imgur.com/YLUnNdX.png
Here are the layout values I have so far the menu item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="wrap_content" android:id="#+id/menu_item"
android:orientation="vertical" android:layout_weight="1"
android:paddingLeft="10dp">
<TextView android:id="#+id/menu_item_title"
android:textSize="20sp"
android:textColor="#android:color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:id="#+id/menu_item_description"
android:textColor="#android:color/darker_gray"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I am using a ListFragment with a custom ListAdapter to return the above layout with the required String values and display it in the list.
Thanks in advance!
You should use themes and styles if you are looking for the text size and color to be the same throughout the app.
http://developer.android.com/guide/topics/ui/themes.html
I want to make an app with a login activity/layout similar to what Facebook app has. What I mean is when text field is focused soft keyboard pushes the entire view up but not squashing a logo. I have tried android:windowSoftInputMode="adjustPan/adjustResize" but it is not what I was trying to achieve.
I found this question on SO perhaps it will make things clearer, but it has no solution to the problem.
I have also tried various layouts types but it soft keyboard only pushes the focused < EditText > up. Please guide me.
UPDATE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#DDDDDD">
<RelativeLayout
android:height="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="fill_parent"
android:background="#ff0000">
<ImageView
android:layout_centerVertical="true"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageView>
</RelativeLayout>
<RelativeLayout
android:height="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent"
android:background="#00ff00">
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff"
android:height="0dp" >
<Button
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Log in"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="4dp"
android:hint="password"
android:inputType="textPassword" >
</EditText>
<EditText
android:id="#+id/editText1"
android:hint="login"
android:padding="4dp"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" ></EditText>
</RelativeLayout>
</LinearLayout>
UPDATE working solution
I can't paste here the entire xml file, but the structure should be enough.
Based on Gabe Sechan's answer.
Layout{
Layout top weight 1
Layout mid weight 1
Layout bot weight 1
}
Child layouts have set to:
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" // should be changed accordingly to your layout design.
And here is a Java code for the activity(keyboard up/down):
View top, mid, bot;
final View activityRootView = findViewById(R.id.loginLayout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { //keyboard up
mid.setVisibility(View.INVISIBLE);
top.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 0f));
bot.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1f));
} else {// keyboard down
// v.setVisibility(View.VISIBLE);
mid.setVisibility(View.VISIBLE);
top.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 2f));
bot.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 3f));
}
}
});
On keyboard up you need to change weights accourding to keyboard up design and on keyboard down change back to the default(layout that you've set via xml/java). I've tested the code on 2.3.x and up.
And don't forget to use android:inputType="textFilter" for the login&password EditText's to remove suggestions on input and save some pixels. In your manifest for the activity android:windowSoftInputMode="adjustResize|stateHidden". stateHidden is used so that keyboard won't be up when activity loads. Hope it helps. Good luck.
They're doing it with relative layouts, adjustResize, and android:layout_centerVertical. Basically, they have a linear layout for their main layout, with 3 equally weighted relative layouts inside of it. Each is set to 0dp height, so they take up equal thirds of the screen. The top RelativeLayout holds the logo, centered vertically. The middle holds the login fields and button, centered vertically one on top of the other. The bottom one holds the copyright text, aligned to bottom. The end result is that when the keyboard comes up, the 3 relative layouts get resized to take 1/3 of the new screen. Then their elements are centered in the new screen.
Remember you need the adjustResize window mode to get this, if you use pan it will just move up and the logo will scroll off center.
In Eclipse, go to File|New|Other and in the Wizard that follows, select Android Activity, then on the next page, select LoginActivity from the list of activities. This has the exact layout you're talking about, and you can use that as a framework. It uses a ScrollView to achieve the effect you're looking for.