Android studio - can't see text in AppTheme - android-studio

I have just started android studio, and I can't seem to see the "Hello World" text in my build:
When I switch to another theme I am able to see the text, what could be the problem?
Edit:
The color is not the same as the background.
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.constraint.ConstraintLayout>
Thank you!

According to the information presented about the problem, you need the closing label of ConstraintLayout
</android.support.constraint.ConstraintLayout>
they stay like this
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
</android.support.constraint.ConstraintLayout>
Or you may need to restart the android studio cache
go to the menu file> restat caches / restart
I hope I've helped

Related

I want to add my website menu in web-view in navigation drawer

I converted my website into an Android web-view using an empty activity. The only issue I'm having right now is displaying my website pages in the form of a menu in the navigation drawer. Please assist me in achieving this.
Here is my Layout Activity-main.xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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:id="#+id/swipeRefreshLayout"
tools:context="com.developer.arsltech.MemberPortal.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="9dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/relativeLayout">
<ImageView
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/no_internet"
android:layout_centerHorizontal="true"
android:id="#+id/noConnectionLogo"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connection"
android:layout_below="#+id/noConnectionLogo"
android:textAlignment="center"
android:textSize="26sp"
android:id="#+id/txtNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Please assist me in achieving this.

Weird white line on top of Action Bar

I implemented a DrawerNavigationView with a BottomNavigationView at the same time, but the problem is the ActionBar... The default fragment is ok enter image description here But changing fragment it creates a weird white line on the top of the ActionBar, which is not anymore in the right position... Do u maybe know why?enter image description here Thank u for help D:
XML Code for main activity container for fragments
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
android:theme="#style/Theme2"
app:itemIconTint="#color/white_darker"
app:itemRippleColor="#color/white_darker"
app:itemTextColor="#color/white_darker"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?android:attr/actionBarSize"
android:fitsSystemWindows="true"
app:headerLayout="#layout/drawer_header"
app:itemTextAppearance="?textAppearanceListItem"
app:menu="#menu/navigation_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
XML code for fragment with the problem (Empty ConstraintLayout)
<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/dark"
tools:context=".HomeUi.Notifications.NotificationsFragment">
</androidx.constraintlayout.widget.ConstraintLayout>
In your styles.xml file try NoActionBar after the parent. Other problem could be that there is a rest of a linearlayout in your fragment.
For who has the same problem in future I found the solution adding as a root a CoordinatorLayout wrapping all the xml code on the main fragment container and using android:fitsSystemWindows="true" on it, everything working fine now!

layout_toStartOf doesn't work fine when the element is gone

Below is code that work fine:
<?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:layout_height="match_parent">
<TextView
android:id="#+id/tv_config_value"
tools:visibility="visible"
android:visibility="gone"
android:layout_toStartOf="#+id/iv_config_arrow"
tools:text="122"
android:layout_centerVertical="true"
android:textSize="12dp"
android:textColor="#44bb11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:src="#mipmap/ic_launcher"
android:id="#+id/iv_config_arrow"
tools:visibility="visible"
android:visibility="gone"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
If I change visibility to invisible,it works fine too.
But if I change visibility to gone,it becomes strange.
I think android:layout_toStartOf cannot find iv_config_arrow because its gone.
whereas in invisible, the view is still there and can be reference by the TextView

How to put textview on top of listview

How do I have textview on top of my listview (code shown below)? I tried many ways of placing the textview but it just does not appear.
<?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"
>
<TextView
android:gravity="center_horizontal"
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:gravity="center_horizontal"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
In your code just add android:text="Maulik Dodia". I have just copy your code added TWO LINES to it. One is above one, Second is android:entries="#array/names". I have also added <string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array> to strings.xml
And It worked for me in preview of Android Studio as well as in Emulator.
Below is my code as well as Screen Shots.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.XXXXXXXXXX.sotestingapp.MainActivity">
<TextView
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Maulik Dodia"/>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/names"
android:gravity="center_horizontal"></ListView>
</LinearLayout>
strings.xml
<resources>
<string name="app_name">SOTestingApp</string>
<string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array>
</resources>
Hope this help.
<?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="wrap_parent"
android:orientation="vertical"
>
<TextView
android:gravity="center"
android:id="#+id/nameheader"
android:text="Hello Android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Please check this if it works.

How place floatingactionbutton on end of layout

I wanna place my floatingactionbutton on the end from the bottom of a relativelayout. How i do this as best and most practical?
Here's a screenshot, how it should look:
This functionality only works when your parent layout is a coordinator layout.This can be achieved using the app:layout_anchor="" and the app:layout_anchorGravity=""
Some thing like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="#id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
Hope this was helpful.
If your parent layout is Relative Layout.
Just use
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>

Resources