I'm getting this error when running my app. Any ideas ? I am using Android Studio and SDK 22.
Process: com.example.sv_laptop03.app, PID: 21717
java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.example.sv_laptop03.app/com.example.sv_laptop03.app.LoggedIn}: android.view.InflateException:Binary XML file line #123: Error inflating class android.support.design.widget.NavigationView
here is the xml its referring to :
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
app:headerLayout="#layout/headerview"
app:menu="#menu/drawer"
app:itemTextColor="#ffffff"/>
</android.support.v4.widget.DrawerLayout>
Headerview.xml :Headerview.xml :Headerview.xml :Headerview.xml :Headerview.xml :Headerview.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#drawable/headerbg"
android:layout_height="200dp"
android:orientation="vertical"><!--
<TextView
android:id="#+id/profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="#ffffff"/>
-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileImage"
android:layout_width="90dp"
android:layout_marginTop="10dp"
android:src="#drawable/snapchainappicon"
app:border_width="2dp"
app:border_color="#2E7D32"
android:layout_gravity="center"
android:layout_height="90dp"/><!--
<TextView
android:id="#+id/viewProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="View Profile"
android:textColor="#ffffff"/>-->
</LinearLayout>
Here is the XML FOR menu/drawer. xml file
<group android:checkableBehavior="single">
<item
android:id="#+id/itemAbout"
android:title="How it works"
android:icon="#drawable/ic_help_black_24dp"/>
<item
android:id="#+id/itemNetworks"
android:title="Friends"
android:icon="#drawable/ic_contacts_black_24dp"/>
<item
android:id="#+id/itemShare"
android:title="Share"
android:icon="#drawable/ic_share_black_24dp"/>
<item
android:id="#+id/itemSettings"
android:title="Settings"
android:icon="#drawable/ic_settings_black_24dp" />
<item
android:id="#+id/itemFeedback"
android:title="Feedback"
android:icon="#drawable/ic_feedback_black_24dp"/>
<item
android:id="#+id/itemLogOut"
android:title="Log out"
android:icon="#drawable/ic_power_settings_new_black_24dp"/>
</group>
</menu>
Check you add your activity on manifest file or not
it might happen if you are trying on lower end devices.
Related
My XML CODE:-
<?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="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="#+id/tvCollege"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="NGF\nCOLLEGE"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/tvNameTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toLeftOf="#id/imgBarTeachers"
android:layout_toRightOf="#id/tvCollege"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<ImageView
android:id="#+id/imgBarTeachers"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_menu" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingRight="10dp"
android:paddingBottom="20dp">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="10dp"
android:src="#drawable/ic_teachers" />
<View
android:layout_width="1dp"
android:layout_height="76dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/tvSubjectTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="#414141"
android:textSize="18sp" />
<TextView
android:id="#+id/tvMobileTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" />
<TextView
android:id="#+id/tvMailTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewMenuTeacher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
My app is running perfectly but when I'm running my app in android 7.0 it's showing me this error.
Error what I'm getting:
Process: com.ngfcet.ngfconnection, PID: 21684
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ngfcet.ngfconnection/com.ngfcet.ngfconnection.activities.TeacherActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class TextView
I think this error is also can formed by firebase because
which textview have +id/tvCollege is not showing any error because I'm not putting any data in it through firebase
Theme for whole application
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/white</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">#android:color/white</item>d
<item name="android:fontFamily">sans-serif-medium</item>
</style>
</resources>
It's too simple. I have removed
<item name="android:fontFamily">sans-serif-medium</item>
from styles.xml
Thanks! It's working perfect now
I spent almost the whole weekend to figure out how to create a table structure with headers for columns and rows and include ImageButtons in the cells of the table. The grid lines should be visible.
I tried lot of different layouts... Grid, Linear, Structured, CoordinatorLayout .... view nested GridViews and so on. But couldn't figure out how to accomplish something like this?
Some kind of nested layout magic?
Create a drawable cell_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<stroke android:width="0.5dp" android:color="#4E4E4E"/>
</shape>
In your styles.xml define your custom cell style
<style name="Cell">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:background">#drawable/cell_shape</item>
<item name="android:gravity">center</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textSize">12sp</item>
</style>
table_layout.xml
<?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">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
style="#style/Cell"
android:text="\"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 1"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 2"
android:textStyle="bold" />
<TextView
style="#style/Cell"
android:text="My Title 3"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
style="#style/Cell"
android:text="Arg 1"
android:textStyle="bold" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
<ImageButton
style="#style/Cell"
android:src="#mipmap/ic_launcher" />
</TableRow>
<!--Next Rows...-->
</TableLayout>
<!--//..-->
</RelativeLayout>
its a simple linear layout with 1 ImageView and 6 TextViews and a ScrollView but TextViews are appearing at the end of the screen and not below ImageView. I have tried editing my dp values in styles.xml but still not working please have a look!!
I have also tried editing my ImageView tags but still not working and don't know why TextViews are appearing at the end of the screen and if I remove ScrollView the texts are not visible.
Layout code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000000"
tools:context="com.example.stan.sportbusinesscard.MainActivity">
<ImageView
android:scaleType="fitStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/photo_description"
android:src="#drawable/photo"
android:id="#+id/image"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text1"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/where" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:autoLink="map"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/when" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dateOf" />
</LinearLayout>
</ScrollView>
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="LightText" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="android:paddingLeft">18dp</item>
<item name="android:paddingRight">18dp</item>
<item name="android:textColor">#aaaaaa</item>
</style>
<style name="TitleText" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="android:paddingLeft">18dp</item>
<item name="android:paddingRight">18dp</item>
<item name="android:paddingTop">20dp</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">#FFD700</item>
</style>
</resources>
You ImageView hight is wrap_content this the reason why your textview are at the bottom of your screen
Try this set static height to your ImageView
<ImageView
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="150dp"
android:contentDescription="#string/photo_description"
android:src="#drawable/photo"
android:id="#+id/image"/>
Try this!
In your <ImageView> scaleType is android:scaleType="fitStart" change it to android:scaleType="fitXY"
Don't use Scrollview as parent view and add android:adjustViewBounds="true" to Imageview for fit.
<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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000000"
>
<ImageView
android:scaleType="fitStart"
android:layout_width="match_parent"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:contentDescription="#string/photo_description"
android:src="#drawable/photo"
android:id="#+id/image"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text1"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/where" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:autoLink="map"/>
<TextView
style="#style/TitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/when" />
<TextView
style="#style/LightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dateOf" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I am trying to make the back button on the toolbar black, but I can't find a way. For some reason I don't have toolBar in my xml file, so there is no way to change the color for me. Please let me know if there is another way.
I have the primaryColor white, but the back button is also white.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="actionMenuTextColor">#color/colorPrimaryDark</item>
</style>
This is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Space
android:layout_width="match_parent"
android:layout_height="40dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/taskNameEditText"
android:textAlignment="center"
android:hint="enter task name"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/scrollLinearLayout">
</LinearLayout>
</HorizontalScrollView>
<Space
android:layout_width="match_parent"
android:layout_height="40dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/fromTimeEditText"
android:layout_weight="1"
android:hint="fromTime"
android:textAlignment="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/toTimeEditText"
android:layout_weight="1"
android:hint="toTime"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
if you are using toolbar then you can change
toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.blue_gray_15), PorterDuff.Mode.SRC_ATOP);
I want to create a layout like this:
I have 3 different images: the background, the white square and the V sign.
How can I position them as in the photo, when I want the box to move from side to side
when onClick is triggered.
I have tried:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/off_background">
<ImageView
android:id="#+id/bottom_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/handle" />
<ImageView
android:id="#+id/upper_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/switch_v" />
</FrameLayout>
which gives me the order correctly, but not posed correctly:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#drawable/off_background">
<ImageView android:id="#+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/handle"
android:src="#drawable/switch_v"
android:layout_gravity="center"
android:scaleType="centerInside"/>
</FrameLayout>
Give this a try:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/off_background" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/bottom_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/handle" />
<ImageView
android:id="#+id/upper_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/switch_v" />
</RelativeLayout>
</RelativeLayout>
Provide android:layout_gravity="center" for ImageView in your xml
You should really be looking at the TobbleButton.
Your layout should look like this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/off_background">
<ToggleButton
android:id="#+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn=""
android:textOff=""
android:background="#drawable/toggle_bg"
/>
</FrameLayout>
And use a selector (toggle_bg) for the background like below
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/toggle_on" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="#drawable/toggle_on" android:state_checked="true" android:state_focused="false"/>
<item android:drawable="#drawable/toggle_off" android:state_checked="false" android:state_pressed="true"/>
<item android:drawable="#drawable/toggle_off" android:state_checked="false" android:state_focused="false"/>
</selector>
This is of course assuming you have the drawables for the different states of the ToggleButton.
Hope that helps.