I have such fragment xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F1F1F1"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollbars="none">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/right_guideline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.92" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/left_guideline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.07" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/logo_guideline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_holder"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:labelFor="#id/first_input"
android:minHeight="48dp"
android:textColorHint="#333333"
app:hintAnimationEnabled="false"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout"
app:layout_constraintLeft_toRightOf="#id/left_guideline"
app:layout_constraintRight_toLeftOf="#id/right_guideline"
app:layout_constraintTop_toBottomOf="#id/logo_guideline">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/login_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:inputType="text"
android:labelFor="#id/login_input"
android:maxLines="1"
android:minHeight="48dp"
android:textColor="#333333"
android:textColorHint="#333333" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_holder"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2.5dp"
android:labelFor="#id/password_holder"
android:minHeight="48dp"
android:textColorHint="#333333"
app:hintTextAppearance="#style/TextAppearance.App.TextInputLayout"
app:layout_constraintLeft_toRightOf="#id/left_guideline"
app:layout_constraintRight_toLeftOf="#id/right_guideline"
app:layout_constraintTop_toBottomOf="#id/login_holder"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#333333">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:labelFor="#id/password_input"
android:maxLines="1"
android:minHeight="48dp"
android:textColor="#333333"
android:textColorHint="#333333" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/login_button"
style="#style/Widget.MaterialComponents.Button.Icon"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="20dp"
android:backgroundTint="#color/colorAccent"
android:textAllCaps="false"
app:layout_constraintLeft_toRightOf="#id/left_guideline"
app:layout_constraintRight_toLeftOf="#id/right_guideline"
app:layout_constraintTop_toBottomOf="#id/password_holder" />
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="#+id/request_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:translationZ="2dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#id/login_button"
app:layout_constraintLeft_toLeftOf="#id/login_button"
app:layout_constraintRight_toRightOf="#id/login_button"
app:layout_constraintTop_toTopOf="#id/login_button"
app:mlpb_arrow_height="2dp"
app:mlpb_arrow_width="7dp"
app:mlpb_enable_circle_background="false"
app:mlpb_progress_stoke_width="2.5dp"
app:mlpb_show_arrow="false" />
<TextView
android:id="#+id/forgot_pass_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textColor="#626262"
android:textSize="16sp"
android:gravity="center"
app:layout_constraintLeft_toRightOf="#id/left_guideline"
app:layout_constraintRight_toLeftOf="#id/right_guideline"
app:layout_constraintTop_toBottomOf="#id/login_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</layout>
and here is test which I'm trying to add:
#RunWith(AndroidJUnit4::class)
class LoginUITest {
#Before
fun setUp() {
launchFragmentInContainer<LoginScreen>(
initialState = Lifecycle.State.STARTED
)
}
#Test
fun testFragmentElements() {
onView(withId(R.id.login_holder)).check(matches(isDisplayed()))
}
#After
fun tearDown() {
//clean up code
}
}
there are problems:
my R. is not visible, red highlighted. Only if I add it manually to import
when I'm trying to launch this test on my emulator does not show any app, only I see in AS status Gradle build
how to check requests in ui tests, like to the api? or it is only about UI?
Maybe I have to add some more dependencies to build.gradle, at this moment I have:
dependecies{
testImplementation 'org.junit.jupiter:junit-jupiter'
debugImplementation 'androidx.fragment:fragment-testing:1.5.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1'
implementation 'androidx.test.espresso:espresso-idling-resource:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.5.1'
}
UPDATE
Also when I interrupt build after 10 minutes I can see such error in the logcat:
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.test.platform.io.PlatformTestStorageRegistry" on path: DexPathList
Related
hi I have to make a view like the below image .
But when i make the parent view transperent , default background is showing like this:
a transperent view is showing behind the main view.
my xml starts like :
<?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="wrap_content"
android:layout_margin="#dimen/_8sdp"
android:background="#color/red"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_50sdp"
android:background="#drawable/rounded_corner_shadow"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="#+id/progressLayout_frame"
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_90sdp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:clickable="true"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<View
android:id="#+id/bgCircle"
android:layout_width="#dimen/_70sdp"
android:layout_height="#dimen/_70sdp"
android:layout_gravity="center"
android:alpha="0.7"
android:background="#color/white"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:clickable="true"
>
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:layout_centerHorizontal="true"
android:background="#drawable/circle_shape"
android:progressDrawable="#drawable/circular_progress_bar" />
<TextView
android:id="#+id/tvTimeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="60dp"
android:text="00:00"
android:textColor="#FFFFFF"
android:textSize="29sp"
app:customTypeFace="roboto_light" />
how can I hide the view behind . why does this layout come ? any suggestions would be helpful . thanks in advance
To remove default background of the dialog...
Step 1:
Create a custom_dialog.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="wrap_content"
android:layout_marginHorizontal="#dimen/_20sdp"
android:paddingHorizontal="#dimen/_25sdp"
android:paddingVertical="#dimen/_25sdp" >
<androidx.constraintlayout.widget.Guideline
android:id="#+id/left_vertical_gl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.02" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/right_vertical_gl"
android:layout_width="match_parent"
android:layout_height="1dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.98" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/center_horizontal_gl"
android:layout_width="match_parent"
android:layout_height="1dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.48" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/top_horizontal_gl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.044" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/end_horizontal_gl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.90" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/segui_black"
android:text="Are You Sure?"
android:textColor="#484A67"
android:textSize="#dimen/_24ssp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/top_horizontal_gl" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_2sdp"
android:layout_marginBottom="12dp"
android:fontFamily="#font/segoe"
android:gravity="center"
android:text="Are you sure you want to sign out?"
android:textColor="#484A67"
android:textSize="#dimen/_11ssp"
app:layout_constraintEnd_toStartOf="#+id/right_vertical_gl"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView9" />
<TextView
android:id="#+id/yesTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_20sdp"
android:fontFamily="#font/segui_semi_bold"
android:padding="#dimen/_5sdp"
android:text="Yes"
android:textColor="#AD7BFF"
app:layout_constraintEnd_toStartOf="#+id/right_vertical_gl"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<TextView
android:id="#+id/noTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_30sdp"
android:fontFamily="#font/segoe"
android:padding="#dimen/_5sdp"
android:text="No"
android:textColor="#6D6E85"
app:layout_constraintBottom_toBottomOf="#+id/yesTv"
app:layout_constraintEnd_toStartOf="#+id/yesTv"
app:layout_constraintTop_toTopOf="#+id/yesTv"
tools:layout_editor_absoluteX="143dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 2:
Go to your dialog activity
Add the below line to your dialog code
popUpDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
Complete code of the dialog
private lateinit var popUpDialog: Dialog
private fun buyLifeLineDialog() {
popUpDialog.setContentView(R.layout.dialog_buy_lifelines)
popUpDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val yesTv = popUpDialog.findViewById<TextView>(R.id.yesTv);
val noTv = popUpDialog.findViewById<TextView>(R.id.noTv);
popUpDialog.show()
yesTv.setOnClickListener {
if (isCheatLl) {
mViewModel.buyCheatLifeline(index,lifeLinesPackagesModel)
}
else{
mViewModel.buyRespawnLifeline(index,lifeLinesPackagesModel)
}
popUpDialog.dismiss()
}
noTv.setOnClickListener {
popUpDialog.dismiss()
}
}
I don't know how do you display this window in your app , but I suppose that you display it as custom dialog , so the problem is that you need to add a transparent theme for your dialog to get the same design or your dialog will fill the transparent spaces with this black color or white depends on your app theme , so to solve this problem you need to add this style in your theme.xml file or style.xml
<style name="AlertDialogCustom" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
and then you create a new custom dialog in your activity like this
//Here i will create new dialog with a custom style which I added in Theme.xml
final AlertDialog dialog2 = new AlertDialog.Builder(MainActivity.this,R.style.AlertDialogCustom).create();
LayoutInflater inflater = getLayoutInflater();
//Here I added my xml file , you can replace test with your own xml file
View convertView = (View) inflater.inflate(R.layout.test, null);
dialog2.setView(convertView);
dialog2.setCancelable(false);
//Here we tell the dialog to display , you can call show() when click a button
dialog2.show();
and here it's my simple design to get a transparent background
<?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="350dp"
android:layout_margin="8dp"
android:background="#android:color/transparent"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl2"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="#+id/progressLayout_frame"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:clickable="true"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<View
android:id="#+id/bgCircle"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:background="#drawable/pers_icon"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:clickable="true">
</RelativeLayout>
</FrameLayout>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="218dp"
tools:layout_editor_absoluteY="129dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Now this is the final result , you can make your own design
I am trying to override xml of stripe to show Edittext inside framelayout horizontally
Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<merge 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">
<com.stripe.android.view.CardBrandView
android:id="#+id/card_brand_view"
android:layout_width="#dimen/card_brand_view_width"
android:layout_height="#dimen/card_brand_view_height"
android:layout_marginTop="#dimen/stripe_card_icon_padding"
android:layout_marginBottom="#dimen/stripe_card_icon_padding"
android:layout_marginEnd="#dimen/stripe_card_icon_padding"
/>
<FrameLayout
android:id="#+id/container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_vertical"
>
<!-- The accessibilityTraversalBefore attribute is ignored in sdk < 22 -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/card_number_text_input_layout"
android:labelFor="#id/card_number_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:visibility="visible"
android:background="#android:color/transparent"
tools:ignore="UnusedAttribute"
android:accessibilityTraversalBefore="#+id/text_input_expiry_date"
android:nextFocusRight="#+id/text_input_expiry_date"
android:nextFocusForward="#+id/text_input_expiry_date"
android:nextFocusDown="#+id/text_input_expiry_date"
android:contentDescription="#string/acc_label_card_number"
android:accessibilityLiveRegion="polite"
app:hintEnabled="false"
style="#style/Stripe.CardInputWidget.TextInputLayout">
<com.stripe.android.view.CardNumberEditText
android:id="#+id/card_number_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="actionNext"
android:hint="#string/card_number_hint"
style="#style/Stripe.CardInputWidget.EditText"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/expiry_date_text_input_layout"
android:labelFor="#id/expiry_date_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/stripe_card_expiry_initial_margin"
android:layout_gravity="start"
android:visibility="visible"
android:background="#android:color/transparent"
tools:ignore="UnusedAttribute"
android:accessibilityTraversalBefore="#+id/text_input_cvc"
android:accessibilityTraversalAfter="#+id/text_input_card_number"
android:nextFocusRight="#+id/text_input_cvc"
android:nextFocusForward="#+id/text_input_cvc"
android:nextFocusDown="#+id/text_input_cvc"
android:nextFocusLeft="#id/text_input_card_number"
android:nextFocusUp="#id/text_input_card_number"
android:contentDescription="#string/acc_label_expiry_date"
android:accessibilityLiveRegion="polite"
app:hintEnabled="false"
style="#style/Stripe.CardInputWidget.TextInputLayout">
<com.stripe.android.view.ExpiryDateEditText
android:id="#+id/expiry_date_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="actionNext"
android:digits="#string/stripe_expiration_date_allowlist"
android:hint="#string/expiry_date_hint"
style="#style/Stripe.CardInputWidget.EditText"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/cvc_text_input_layout"
android:labelFor="#id/cvc_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/stripe_card_cvc_initial_margin"
android:layout_gravity="start"
android:background="#android:color/transparent"
tools:ignore="UnusedAttribute"
android:accessibilityTraversalAfter="#+id/text_input_expiry_date"
android:nextFocusLeft="#id/text_input_expiry_date"
android:nextFocusUp="#id/text_input_expiry_date"
android:contentDescription="#string/cvc_number_hint"
android:accessibilityLiveRegion="polite"
app:hintEnabled="false"
style="#style/Stripe.CardInputWidget.TextInputLayout">
<com.stripe.android.view.CvcEditText
android:id="#+id/cvc_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="actionDone"
style="#style/Stripe.CardInputWidget.EditText"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/postal_code_text_input_layout"
android:labelFor="#id/postal_code_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginStart="#dimen/stripe_card_cvc_initial_margin"
android:layout_gravity="start"
android:background="#android:color/transparent"
tools:ignore="UnusedAttribute"
android:accessibilityTraversalAfter="#+id/text_input_cvc"
android:nextFocusLeft="#id/text_input_cvc"
android:nextFocusUp="#id/text_input_cvc"
android:contentDescription="#string/address_label_postal_code"
android:accessibilityLiveRegion="polite"
app:hintEnabled="false"
style="#style/Stripe.CardInputWidget.TextInputLayout">
<com.stripe.android.view.PostalCodeEditText
android:id="#+id/postal_code_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="actionDone"
android:enabled="false"
style="#style/Stripe.CardInputWidget.EditText"
/>
</com.google.android.material.textfield.TextInputLayout>
</FrameLayout>
</merge>
Here is the code I have used from stripe library and I am trying to override this, my requirement is to show all editText fields as horizontally with match_parent and show edittext horizontally into 4 rows
Card Number
CVC
Date Expiry
Postal Code
Thanks
Regards
Using CardMultiLineWidget resolves my problem
https://stripe.dev/stripe-android/com/stripe/android/view/CardMultilineWidget.html
I am new to Android development so excuse me if I ask some dumb questions but I really can't figure out why whenever I switch from a relative layout or linear to a DrawerLayout my design view goes blank and only said "android....DrawerLayout".i loose all of the buttons textfields all of it goes away! I added all of the dependencies necessary to use it. All I need this drawer layout is to add a navigation view to my main screen. I have tried the but it still nothing shows in the design view so I can't really lay things out properly without seeing how it is going to look! Any help will be really appreciated!
enter image description here
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC809fff"
android:padding="10dp">
<ImageView
android:id="#+id/weatherView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="false"
android:contextClickable="true"
android:padding="10dp"
android:src="#drawable/weather" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/cardview_dark_background"
android:padding="11dp"
android:visibility="visible" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:text="Weather"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC809fff"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/news" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:outlineAmbientShadowColor="#ff3300
"
android:visibility="visible">
</View>
<TextView
android:id="#+id/textview5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:text="News"
android:textColor="#ffffff"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC000000"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:src="#drawable/events_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</View>
<TextView
android:id="#+id/eventsTextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Events"
android:textColor="#color/cardview_light_background"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CC000000"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="#drawable/trending_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</View>
<TextView
android:id="#+id/secondview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Hottest"
android:textColor="#color/cardview_light_background"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
MY DEPENDENCIES ARE THE FOLLOWING:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-v4:28.0.0'
}
--------- BUILD.GRADLE:PROJECT---------
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Most times this is usually because of Android studio cache issues. You can try to invalidate and restart your Android Studio by going to:
File->Invalide Caches / Restart.
Once you have added all dependencies, this should solve your problem.
I hope this helps.
If you want to use CardView you must include its dependency
Add this dependency
implementation 'com.android.support:cardview-v7:28.0.0'
i am having problem, failed to instantiate one or more classes.Following classes cannot be instantiate .
android.support.v7.widget.AppCompatTextview
There it is my xml file
<?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_content"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/iv_comment_owner_display"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/facebook" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#android:color/black"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text=""
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
AppCompatTextView was added in appcompat-v7:22.1.0
Please check you appcompat version. You have to update your gradle file with this.
clean/Rebuild project from Android Studio,it might help.
If it doesn't try to invalidate caches and restart android studio.
If you have not done,
Try adding the dependencies in your build.gradle(Module:App)
please check the version according to your app
dependencies {
compile 'com.android.support:design:25.3.1'
}
Try putting this code in your layout
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello world"
android:textSize="18dp"
/>
because i see no AppCompatTextView in your layout.
As I have updated to Android Studio 2.2, I tried new ConstraintLayout to create a simple Activity. Surprisingly, alpha 8 (currently the most up-to-date) is really buggy, causing multiple resets in the blueprint stage.
The main problem is that all items that I have added through Blueprint are not constrained in the Design tab:
Design and Blueprint
The dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'org.apache.openejb:openejb-telnet:3.1.4'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
}
I do remember unchecking or checking some checkmark when creating new Empty Activity. Does it have to do with that?
Activity class extends Activity.
Please help me get rid of bugs of new layout constructor.
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_telnet"
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="xx.xxx.xxxx.TelnetActivity">
<TextView
android:text="IP:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_IP"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<EditText
android:layout_width="180dp"
android:layout_height="16dp"
android:inputType="text|textPersonName"
android:ems="10"
android:id="#+id/et_IP"
android:layout_marginStart="80dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/tv_IP" android:layout_marginLeft="80dp"
/>
<TextView
android:text="Port:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_port"
app:layout_constraintLeft_toLeftOf="#+id/tv_IP"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/tv_IP"/>
<EditText
android:layout_width="180dp"
android:layout_height="16dp"
android:inputType="number"
android:ems="10"
android:id="#+id/et_port"
app:layout_constraintBottom_toBottomOf="#+id/tv_port"
app:layout_constraintLeft_toLeftOf="#+id/et_IP"
/>
<Button
android:text="Connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_connect"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/et_port"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintRight_creator="1" tools:layout_constraintLeft_creator="1"
android:onClick="connect (TelnetActivity)"/>
<TextView
android:text="Status:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/btn_connect"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:text="Disconnected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_status"
app:layout_constraintTop_toTopOf="#+id/textView3"
app:layout_constraintLeft_toLeftOf="#+id/et_port"/>
<TextView
android:text="Send msg:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/textView3"
app:layout_constraintLeft_toLeftOf="#+id/textView3"/>
<EditText
android:layout_height="16dp"
android:ems="10"
android:id="#+id/et_sendMsg"
android:layout_width="180dp" android:inputType="text"
app:layout_constraintBottom_toBottomOf="#+id/textView4"
app:layout_constraintRight_toRightOf="#+id/et_port"/>
<TextView
android:text="Response:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/textView4"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_response"
app:layout_constraintBottom_toBottomOf="#+id/textView5"
app:layout_constraintLeft_toLeftOf="#+id/tv_status"
app:layout_constraintTop_toTopOf="#+id/textView5"/>
<Button
android:text="OK"
android:layout_width="88dp"
android:layout_height="48dp"
android:id="#+id/btn_sendMsg"
app:layout_constraintBottom_toBottomOf="#+id/et_sendMsg"
app:layout_constraintTop_toTopOf="#+id/et_sendMsg"
android:layout_marginBottom="16dp"
android:layout_marginStart="24dp"
app:layout_constraintLeft_toRightOf="#+id/et_port" android:layout_marginLeft="24dp"
app:layout_constraintVertical_bias="0.44" android:onClick="sendMsg (TelnetActivity)"/>
</android.support.constraint.ConstraintLayout>
PS: Restarting Android Studio helped with getting all the elements on the right places, until I moved any of them. After that - everything collapses again.
If you updated from alpha7 to alpha8 (which is probably the case if you downloaded Android Studio 2.2), you may need to rebuild your project and/or do File->Invalidate Caches in Studio -- though restarting Studio should have been enough. Tell me if that works for you.
Also; on which environment are you running? (Windows, Mac, Linux, which JVM...)