After lock my screen and unlock pressing the turn off button my webview is reloaded.
I have found that problem is with onResume()
#Override
protected void onResume() {
super.onResume();
mWebView.onResume();
mWebView.resumeTimers();
}
Reload is happen only with webview, as i can see navigation bar at the bottom is untouched. So how to prevent reloading webview also i will need onResume() for future use so removing is not solution.
Here is Activity layout
<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:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:windowTranslucentNavigation="false"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeRefresh"
android:layout_width="0dp"
android:layout_height="0dp"
android:overScrollMode="never"
android:soundEffectsEnabled="true"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#id/BottomLayout"
app:layout_constraintEnd_toEndOf="#id/BottomLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:scrollbars="none"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<include
android:id="#+id/netCon"
layout="#layout/network_connection" />
<include
android:id="#+id/srvCon"
layout="#layout/server_connection" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/BottomLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:animateLayoutChanges="true"
android:background="#drawable/border_top_bottom_menu"
android:clipToPadding="false"
android:duplicateParentState="false"
android:fitsSystemWindows="false"
android:focusableInTouchMode="false"
android:theme="#style/bottom_navigation_menu"
android:visibility="visible"
app:barrierAllowsGoneWidgets="true"
app:itemHorizontalTranslationEnabled="false"
app:itemIconSize="22dp"
app:itemIconTint="#color/drawer_item"
app:itemTextColor="#color/drawer_item"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toTopOf="#id/Notification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
<LinearLayout
android:id="#+id/Notification"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/notification_offline"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/notificationText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center|center_vertical"
android:indeterminate="false"
android:theme="#style/progressWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Try saving the state of the webview and only loading it when savedstate is not null
#Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
web.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}
Related
I have a bookmark button in the action bar which is not clickable when I open a bottom sheet by clicking a button (the button is in fragment).
Here is the code :
activity_learn.xml
<?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=".learn.LearnActivity">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
mcq_fragment.xml
<?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"
android:background="#color/light_cyan">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/ic_close"
style="#style/ic_close"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_close"
tools:targetApi="lollipop" />
<ProgressBar
android:id="#+id/determinateBar"
style="#style/progressBar"
app:layout_constraintEnd_toStartOf="#+id/cardNumber"
app:layout_constraintStart_toEndOf="#+id/ic_close"
app:layout_constraintTop_toTopOf="parent" />
......more code ......
<com.adithya.memoneet.utils.FButton
android:id="#+id/check_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:fontFamily="#font/quando"
android:text="Check"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
app:buttonColor="#color/light_gray"
app:cornerRadius="30dp"
app:layout_constraintBottom_toTopOf="#+id/adView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear_layout"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
correct_wrong_bottom_sheet_dialog.xml
<?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"
app:layout_behavior="#string/bottom_sheet_behavior"
app:behavior_hideable= "true"
android:id="#+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:fontFamily="#font/fredoka_one"
android:lineSpacingExtra="1sp"
android:textColor="#color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Oops! Correct Answer is: \nHeart" />
<ozaydin.serkan.com.image_zoom_view.ImageViewZoom
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:src="#drawable/ic_memoneet"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview" />
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="#+id/youtube_player_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:visibility="gone"
app:autoPlay="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image"
app:showFullScreenButton="true"
app:showYouTubeButton="false" />
<com.adithya.memoneet.utils.FButton
android:id="#+id/continue_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="30dp"
android:fontFamily="#font/quando"
android:text="Continue"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
app:buttonColor="#color/light_gray"
app:cornerRadius="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/youtube_player_view"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
McqFragment.java
//below function is called when the user clicks the button in MCQ fragment
public static void showCorrectWrongBottomSheetDialog(final FragmentActivity activity, String answer, String explanation, boolean correct, String subjectType, final CallBackListener callBackListener) {
try {
final BottomSheetDialog dialog = new BottomSheetDialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setDimAmount(0.01f);
dialog.setContentView(R.layout.correct_wrong_bottom_sheet_dialog);
dialog.setCancelable(false);
ConstraintLayout bottom_layout = dialog.findViewById(R.id.bottom_layout);
FButton continue_button = dialog.findViewById(R.id.continue_button);
TextView textview = dialog.findViewById(R.id.textview);
String finalExplanation;
AppCompatImageView imageView = dialog.findViewById(R.id.image);
..more code..
}
when the bottom sheet is opened in mcq fragment I am not able to click the bookmark button in action bar
i am facing some problems with anable and disable traffic TYPE on the google map when OnMapReady.I have tow differents MAP_TYPE_NORMAL and MAP_TYPE_HYBRID.
what i want is to setOnclickListener when button is clicked.
my button code:
maptrafic.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(map.getMapType() == GoogleMap.MAP_TYPE_NORMAL || map.getMapType() == GoogleMap.MAP_TYPE_HYBRID){
map.setTrafficEnabled(true);
maptrafic.setImageResource(R.drawable.trafficmap_on);
}
else {
map.setTrafficEnabled(false);
maptrafic.setImageResource(R.drawable.trafficmap_off);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
});
also, i am working on googlemap using REST API i have successfuly create windowsInfoMarker but what i need is when map ready is to see the marker name only not all information like windowsInfoMarker but only Markers with name.
my MapActivity code shared from drive
MapActivity.java
my activity_map.xml
<RelativeLayout 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:orientation="vertical"
android:id="#+id/drawer"
android:layout_height="match_parent"
tools:context=".activities.MapActivity">
<RelativeLayout
android:id="#+id/mapfloating"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--inclusion de la carte-->
<include layout="#layout/include_main_map" />
<!--fin inclusion de la carte-->
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="#+id/mainFloatingBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_margin="25dp"
app:fab_labelStyle="#style/custom_floating_buttons"
android:layout_alignParentBottom="true"
app:fab_addButtonColorNormal="#color/blue">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/evennements"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_icon="#drawable/icon_events"
app:fab_title="Evennements"
android:background="#drawable/cerclebackground"
app:fab_colorNormal="#color/purple_500"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/historiques"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_icon="#drawable/icon_history"
app:fab_title="Historique"
android:background="#drawable/cerclebackground"
app:fab_colorNormal="#color/purple_500"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/reglages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_icon="#drawable/icon_setup"
app:fab_title="Reglages"
android:background="#drawable/cerclebackground"
app:fab_colorNormal="#color/purple_500"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/aide_support"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_icon="#drawable/icon_support"
app:fab_title="Aide/Support"
android:background="#drawable/cerclebackground"
app:fab_colorNormal="#color/purple_500"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingPopUpLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:contentDescription="#string/app_name"
app:fab_colorDisabled="#color/white"
app:fab_colorNormal="#color/white"
app:fab_colorPressed="#color/blue"
app:fab_icon="#drawable/ic_menu_24" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingPopUpRight"
style="#style/custom_floating_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:contentDescription="#string/app_name"
app:fab_colorDisabled="#color/white"
app:fab_colorNormal="#color/white"
app:fab_colorPressed="#color/blue"
app:fab_icon="#drawable/ic_baseline_notifications_active_24" />
</RelativeLayout>
</RelativeLayout>
my include_mean_map
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/content_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true" />
<LinearLayout
android:id="#+id/zoomio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="#+id/fonctio"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="290dp"
android:layout_marginStart="9dp">
<ImageButton
android:id="#+id/zoom_in"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/zoom_in_selector"
android:layout_marginStart="4dp"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/zoom_out"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="4dp"
android:layout_marginTop="5dp"
android:src="#drawable/zoom_out_selector"
tools:ignore="ContentDescription,TouchTargetSizeCheck,SpeakableTextPresentCheck" />
</LinearLayout>
<LinearLayout
android:id="#+id/fonctio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="70dp"
android:layout_marginStart="9dp">
<ImageButton
android:id="#+id/showtails"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:src="#drawable/tail_active"
tools:ignore="ContentDescription,TouchTargetSizeCheck" />
<ImageButton
android:id="#+id/autozoom"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/icon2022"
android:layout_marginTop="5dp"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/geofences"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/geofence_active"
android:layout_marginTop="5dp"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/map_layer"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:src="#drawable/map_layer_change_icon_inactive"
tools:ignore="ContentDescription,TouchTargetSizeCheck" />
<ImageButton
android:id="#+id/map_trafic"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/grey_round_rect"
android:layout_marginTop="5dp"
android:src="#drawable/trafficmap_on"
tools:ignore="ContentDescription" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/loading_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:visibility="gone"
android:gravity="center">
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminate="true"
style="#style/Widget.MaterialProgressBar.ProgressBar.Horizontal" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/nodata_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:visibility="gone"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/noMapData"/>
</RelativeLayout>
</RelativeLayout>
if you have any idea please don't ready only i need help. any idea are welcome.
if you need more details juste ask i am online 24/7 each second.
I have been searching for a long time, but none of the answers were helpful.
I'm making a chat app. When the user clicks on input edit text the keyboard shows up, and I want to automatically scroll to the bottom of scroll view, but it does not work as expected. It looks like it thinks that the scrollview has different dimensions than it really has. (probably doesn't realize that keyboard is taking some space)
When keyboard is hidden, programitacally scrolling to the bottom works as expected.
This is what i have now:
In manifest:
<activity
android:name=".ChatActivity"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait" />
In activity:
messageEditText.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View v, boolean hasFocus)
{
if (!hasFocus)
{
HideKeyboard(v);
// ScrollToBottom ();
}
else
{
ScrollToBottom();
messagesScrollView.post(new Runnable() {
#Override
public void run() {
messageEditText.requestFocus();
}
});
ScrollToBottom();
}
}
});
private void ScrollToBottom ()
{
messagesLinearLayout.requestLayout();
messagesLinearLayout.post(new Runnable() {
#Override
public void run() {
messagesScrollView.scrollTo(0, messagesScrollView.getBottom());
}
});
}
Layout file:
<?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"
android:background="#color/black"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context=".ChatActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.LetsGOFriends.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="66dp"
android:background="#242A2F"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetEnd="0dp"
app:buttonGravity="center_vertical"
app:popupTheme="#style/Theme.LetsGOFriends.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|start">
<TextView
android:id="#+id/trainerNameChat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/profilePictureImageView"
android:layout_marginStart="10dp"
android:layout_marginTop="-2dp"
android:layout_toEndOf="#+id/profilePictureImageView"
android:maxLines="1"
android:textSize="14sp"
android:text="LoriMontana"
android:textColor="#color/white" />
<TextView
android:id="#+id/trainerCodeChat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/profilePictureImageView"
android:layout_alignStart="#+id/trainerNameChat"
android:layout_marginBottom="-2dp"
android:layout_marginStart="0dp"
android:maxLines="1"
android:textSize="14sp"
android:text="0467 0321 3849"
android:textColor="#color/white" />
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/profilePictureImageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="15dp"
android:layout_marginStart="0dp"
android:layout_marginTop="15dp"
android:padding="1dp"
app:shapeAppearanceOverlay="#style/roundedImageViewRounded"
app:srcCompat="#drawable/ic_default_profile_picture"
app:strokeColor="#484848"
app:strokeWidth="1dp" />
<ImageView
android:id="#+id/languageFlagChatImageView"
android:layout_width="18dp"
android:layout_height="16dp"
android:layout_alignBottom="#+id/trainerNameChat"
android:layout_alignTop="#+id/trainerNameChat"
android:layout_marginBottom="4dp"
android:layout_marginStart="5dp"
android:layout_marginTop="4dp"
android:layout_toEndOf="#+id/trainerNameChat"
tools:srcCompat="#tools:sample/avatars" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:id="#+id/messagesScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="-15dp"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="#+id/cardView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/appBarLayout">
<LinearLayout
android:id="#+id/messagesLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusableInTouchMode="true"
android:paddingBottom="20dp"
android:paddingTop="5dp"
android:orientation="vertical"
android:focusable="true" />
</ScrollView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout2"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
app:boxBackgroundColor="#242A2F"
app:boxCornerRadiusBottomEnd="15dp"
app:boxCornerRadiusBottomStart="15dp"
app:boxCornerRadiusTopEnd="15dp"
app:boxCornerRadiusTopStart="15dp"
app:boxStrokeColor="#color/teal_700"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:endIconContentDescription="Send"
app:endIconDrawable="#drawable/ic_baseline_send_24"
app:endIconMode="custom"
app:endIconTint="#color/white"
app:hintEnabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Enter your message.."
android:maxLength="250"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="#color/white"
android:textColorHint="#D3D3D3" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
I think it's something wrong with layout file.
Try this code for scrolling down:
messagesScrollView.fullScroll(ScrollView.FOCUS_DOWN);
I have the following layout for a video player:
video_view.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
android:id="#+id/aspectRatioLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<SurfaceView
android:id="#+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/posterImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/poster_image_description" />
<com.google.android.exoplayer2.ui.SubtitleView
android:id="#+id/subtitleView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.exoplayer2.ui.PlayerControlView
android:id="#+id/nativeControls"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.google.android.exoplayer2.ui.PlayerControlView>
<com.sdk.adapters.controls.ControlBar
android:id="#+id/controls"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.sdk.adapters.controls.ControlBar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/messageOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#80000000">
<TextView
android:id="#+id/messageOverlayText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/message_overlay"
android:textColor="#android:color/white"
android:textSize="30sp" />
</FrameLayout>
</FrameLayout>
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
</FrameLayout>
The ControlBar is defined as:
control_bar_view.xml
<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"
android:background="#80000000">
<!-- BEGIN: Strut -->
<View
android:id="#+id/exitPlaceholder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1" />
<!-- END: Strut -->
<TextView
android:id="#+id/broadcastName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/broadcast_name"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#id/castButton"
app:layout_constraintStart_toEndOf="#id/exitPlaceholder"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/siteName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/site_name"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#id/castButton"
app:layout_constraintStart_toEndOf="#id/exitPlaceholder"
app:layout_constraintTop_toBottomOf="#id/broadcastName" />
<ImageButton
android:id="#+id/castButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:contentDescription="#string/send_to_google_chromecast"
android:visibility="invisible"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/airplayButton"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/airplayButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:contentDescription="#string/send_to_apple_airplay"
android:visibility="invisible"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/optionsButton"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/optionsButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:contentDescription="#string/fullscreen"
android:scaleType="fitStart"
android:src="#drawable/closed_caption_gray"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/skipBackButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/skip_back_button"
android:scaleType="fitStart"
android:src="#drawable/back_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/playPauseToggle"
app:layout_constraintHeight_percent="0.20"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/playPauseToggle"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/play_button"
android:scaleType="fitStart"
android:src="#drawable/play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/skipForwardButton"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toEndOf="#id/skipBackButton"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/skipForwardButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/skip_forward_button"
android:scaleType="fitStart"
android:src="#drawable/forward_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.20"
app:layout_constraintStart_toEndOf="#id/playPauseToggle"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/currentTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="10dp"
android:text="#string/null_time"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#id/seekBar"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/remainingTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="10dp"
android:text="#string/null_time"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#id/seekBar"
app:layout_constraintEnd_toEndOf="parent" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="0dp"
android:layout_height="0dp"
android:progress="50"
android:progressDrawable="#drawable/seek_bar"
android:thumb="#drawable/seek_thumb"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/fullscreenButton"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/fullscreenButton"
app:layout_constraintVertical_bias="0.0" />
<ImageButton
android:id="#+id/fullscreenButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:contentDescription="#string/fullscreen"
android:scaleType="fitStart"
android:src="#drawable/fullscreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.1" />
</androidx.constraintlayout.widget.ConstraintLayout>
In the layout editor in Android Studio, this looks good:
However when I run an actual app, the ControlBar (and only the ControlBar) isn't filling the screen! Everything else stretches to fill the screen perfectly:
What am I doing wrong?
If it helps, the ControlBar is a custom View which extends ConstraintLayout. Here's what the initialization code looks like:
ControlBar.java
public class ControlBar extends ConstraintLayout
{
private BFPlayer player;
private TextView broadcastName;
// ... references for the various subviews ...
private ImageButton fullscreenButton;
public ControlBar ( Context context )
{
super(context);
init(context);
}
public ControlBar ( Context context, AttributeSet attrs )
{
super(context, attrs);
init(context);
}
public ControlBar ( Context context, AttributeSet attrs, int defStyleAttr )
{
super(context, attrs, defStyleAttr);
init(context);
}
private void init ( Context context )
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.bf_control_bar_view, null);
addView(view);
broadcastName = findViewById(R.id.broadcastName);
// ... grab references to the various buttons ...
fullscreenButton = findViewById(R.id.fullscreenButton);
// ... set up listeners for the various buttons ...
}
// ... The rest of the class ...
}
What am I doing wrong? I'm sure it's something simple, but I've been staring for a minute and can't figure it out. (Note: I'm pretty new to Android development, and not very experienced. My job has me changing platforms and programming languages very often)
You're not telling it what the parent is when you inflate your View, so it doesn't apply the LayoutParams correctly:
View view = inflater.inflate(R.layout.bf_control_bar_view, null);
addView(view);
Instead, tell it to inflate directly into the parent:
View view = inflater.inflate(R.layout.bf_control_bar_view, this);
I have two radiobutton groups that need to be initialized when loading the screen, so I used this code:
mVisibilityPublic.setChecked(true);
But when I load the screen I get the following (first is the wrong behavior, second is the expected one):
I've tried with all these:
mVisibilityPublic.setSelected(true);
mVisibilityPublic.performClick();
mVisibilityPublic.setActivated(true);
mVisibilityPublic.invalidate();
mVisibilityPublic.requestLayout();
But I get the same result.
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="#dimen/form_vertical_spacing"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".createevent.CreateEventActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/create_event_privacy"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/create_visibility_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/createevent_visibility_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_public_event"/>
<RadioButton
android:id="#+id/createevent_visibility_private"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_private_event"/>
<RadioButton
android:id="#+id/createevent_visibility_ppv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv"/>
</RadioGroup>
<LinearLayout
android:id="#+id/ppv_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/create_event_ppv_section"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.currency.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.myapp.ui.AutoCompleteCombo
android:id="#+id/ppv.currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_currency">
</com.myapp.ui.AutoCompleteCombo>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.price.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="#+id/ppv.price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_price"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioGroup
android:id="#+id/ppv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/ppv_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_allcountries"/>
<RadioButton
android:id="#+id/ppv_allexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_except"/>
<RadioButton
android:id="#+id/ppv_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_some"/>
</RadioGroup>
<com.myapp.countries.CountriesMultiCombo
android:id="#+id/create.ppv.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/general_info"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="-32dp"
android:layout_marginRight="-32dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#color/colorDivider"
/>
<LinearLayout
android:id="#+id/geoblock_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/geo_blocking_settings_title"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/geo_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/geo_none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_none"/>
<RadioButton
android:id="#+id/geo_blockonly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_only"/>
<RadioButton
android:id="#+id/geo_blockexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_all_except"/>
</RadioGroup>
<com.myapp.createevent.countries.CountriesMultiCombo
android:id="#+id/create.geo.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout> <Button
android:id="#+id/test_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLICK ME"/>
</LinearLayout>
</ScrollView>
Note that if I select the option manually (like I did with the second example in the image) I get the proper result. Its only if I do it programmatically that its missing the inner circle.
public class TestFragment extends Fragment {
private Unbinder mUnbinder;
#BindView(R.id.createevent_visibility_public)
RadioButton mVisibilityPublic;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_advanced_opts, container, false);
mUnbinder = ButterKnife.bind(this, inflate);
return inflate;
}
public static TestFragment newInstance(int tvId, int eventId) {
TestFragment testFragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(TV_ARGUMENT, tvId);
args.putInt(EVENTID_ARGUMENT, eventId);
testFragment.setArguments(args);
return testFragment;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mVisibilityPublic.setChecked(true);
}
}