Move dropdown menu to the right - android

I work on an old Android project, I use a compileSdkVersion 16. I have put a SeekBar (a slider) in a dropdown menu. It works perfectly but my button, for displaying the dropdown menu is on the left and I want it on the right, like a parameter button in the Navigation Drawer Activity (the 3 vertically dot).
In my main activity I have thise :
ActionBar actionBar = getActionBar();
DropDown dropDown = new DropDown(this,"Controls","Power", "Tag Filter");
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(dropDown, this);
I use two layout, one for the button in the action bar :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end">
<TextView android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Controls"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
An another one for my dropdown menu :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/seekBarTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="TextView"
android:textColor="#FFFFFF" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/seekBarTextView"
android:layout_weight="1" />
</LinearLayout>
[...]
</RelativeLayout>
I don't know how to put my button to the right, actually it's on the left, near the application name and I want to put it on the opposite.
I have this :
But I want this :
Edit :
My gradle file :
apply plugin: 'com.android.application'
def AAVersion = "4.3.0" // change this to your desired version, for example the latest stable: 4.2.0
android {
compileSdkVersion 16
buildToolsVersion '25.0.0'
//buildToolsVersion '25.3.1'
defaultConfig {
applicationId "com.company.dpdencoder.uhu"
minSdkVersion 14
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.guava:guava:15.0'
compile files('libs/jdom.jar')
// For Hexa coding/décoding
compile 'commons-codec:commons-codec:1.10'
compile files('libs/OpenApi_1.1.2.61_Common.jar')
compile files('libs/OpenApi_1.1.2.61_IaM.jar')
compile files('libs/OpenApi_1.1.2.61_IoT.jar')
}

Toolbar is advanced version of ActionBar. Use Toolbar instead of ActionBar.
Customize the Toolbar as your wish. And set it as ActionBar.
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Don't forget to use Theme.AppCompat.Light.NoActionBar theme as your activity theme.
More info about Toolbar: https://developer.android.com/reference/android/widget/Toolbar.html

Related

Constraint Layout version > 2.0.1 does not follow guildline rules

I am experiencing layout issues when trying to use the latest versions of constraint layout. It seems to not follow guideline rules. Is this a bug in the library? My project uses many guidelines and to change every one of them would be a huge pain. Anyone know if there is a work around of am I doing this wrong? This layout issue seems to happen in versions greater than constraint layout 2.0.1.
Constraint layout v 1.1.3
Constraint Layout v 2.0.4 - the location icon is behind my widget constraint layout
MainActivity layout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/edit_text_message_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#null"
android:hint="Please Type Something"
android:maxHeight="100dp"
android:minHeight="56dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="13dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<requestFocus />
</androidx.appcompat.widget.AppCompatEditText>
<RelativeLayout
android:id="#+id/mic_container"
android:layout_width="140dp"
android:layout_height="140dp"
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toTopOf="#+id/edit_text_message_input"
app:layout_constraintLeft_toLeftOf="#+id/mic_icon_guideline"
app:layout_constraintRight_toRightOf="#+id/mic_icon_guideline">
<CheckBox
android:layout_centerInParent="true"
android:id="#+id/button_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:button="#drawable/navigation_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mic_icon_guideline"
app:layout_constraintGuide_end="28dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/attachment_icon_container"
android:layout_width="match_parent"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input">
<CheckBox
android:id="#+id/button_add_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:button="#drawable/add_location_button"
app:layout_constraintLeft_toRightOf="#+id/button_remove_location"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/button_remove_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:button="#drawable/remove_location_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/button_add_location"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.test_constraint_project"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "com.google.android.material:material:1.2.1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
The RelativeLayout mic_container has the following constraints:
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toTopOf="#+id/edit_text_message_input"
It doesn't seem right that the top of one view should be constrained to the bottom of another and the bottom of the first view should be constrainted to the top of the second. This is really an invalid situation and I think that you are seeing ConstraintLayout resolving this differently between the two versions.
If you state the following as constraints:
app:layout_constraintTop_toTopOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toBottomOf="#+id/edit_text_message_input"
I think that you will see mic_container positioned appropriately. You will have to determine if this solves all of your problems or not.

FAB: Drawable already belongs to another owner

I added two floating action buttons on a fragment but I always get following error:
Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_weight="1"
android:id="#+id/scrollView"
android:layout_marginRight="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout_main_account">
<TextView
android:text="Name"
android:textStyle="bold"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_activity_main_account_name_label"/>
<EditText
android:enabled="false"
android:inputType="none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_activity_main_account_name_label_value"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="0dp"/>
<android.support.design.widget.FloatingActionButton
android:backgroundTint="#000"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_edit_account"
android:id="#+id/fbtn_activity_main_account_edit_account"/>
<android.support.design.widget.FloatingActionButton
android:backgroundTint="#000"
android:layout_marginBottom="5dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_home_account"
android:id="#+id/fbtn_activity_main_account_manage_addresses"
app:layout_anchor="#id/fbtn_activity_main_account_edit_account"/>
</LinearLayout>
</RelativeLayout>
drawable -> ic_edit_account.xml
<vector android:height="24dp" android:viewportHeight="60.017"
android:viewportWidth="60.017" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M59.144,3.731l-2.85,-2.851c-1.164,-1.161 -3.057,-1.162 -4.221,0.001l-3.126,3.126H0v56h56V11.097l0.305,-0.305l0,0l2.839,-2.839C60.308,6.789 60.308,4.895 59.144,3.731zM20.047,36.759l3.22,3.22l-4.428,1.208L20.047,36.759zM52.062,12.206L47.82,7.964l1.414,-1.414l4.243,4.242L52.062,12.206zM50.648,13.62L25.192,39.076l-4.242,-4.242L46.406,9.378L50.648,13.62zM54,13.097v44.91H2v-52h44.947L18.829,34.127l-0.188,0.188l-2.121,7.779l-1.226,1.226c-0.391,0.391 -0.391,1.023 0,1.414c0.195,0.195 0.451,0.293 0.707,0.293s0.512,-0.098 0.707,-0.293l1.226,-1.226l7.779,-2.123l26.351,-26.35h0l0.447,-0.447L54,13.097zM57.73,6.539l-2.839,2.839l-4.243,-4.243l2.839,-2.839c0.384,-0.384 1.009,-0.383 1.393,0l2.85,2.85C58.114,5.529 58.114,6.155 57.73,6.539z"/>
</vector>
drawable -> ic_home_account.xml
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M506.555,208.064L263.859,30.367c-4.68,-3.426 -11.038,-3.426 -15.716,0L5.445,208.064c-5.928,4.341 -7.216,12.665 -2.875,18.593s12.666,7.214 18.593,2.875L256,57.588l234.837,171.943c2.368,1.735 5.12,2.57 7.848,2.57c4.096,0 8.138,-1.885 10.744,-5.445C513.771,220.729 512.483,212.405 506.555,208.064z"/>
<path android:fillColor="#FFFFFFFF" android:pathData="M442.246,232.543c-7.346,0 -13.303,5.956 -13.303,13.303v211.749H322.521V342.009c0,-36.68 -29.842,-66.52 -66.52,-66.52s-66.52,29.842 -66.52,66.52v115.587H83.058V245.847c0,-7.347 -5.957,-13.303 -13.303,-13.303s-13.303,5.956 -13.303,13.303v225.053c0,7.347 5.957,13.303 13.303,13.303h133.029c6.996,0 12.721,-5.405 13.251,-12.267c0.032,-0.311 0.052,-0.651 0.052,-1.036v-128.89c0,-22.009 17.905,-39.914 39.914,-39.914s39.914,17.906 39.914,39.914v128.89c0,0.383 0.02,0.717 0.052,1.024c0.524,6.867 6.251,12.279 13.251,12.279h133.029c7.347,0 13.303,-5.956 13.303,-13.303V245.847C455.549,238.499 449.593,232.543 442.246,232.543z"/>
</vector>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.atta"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
// retrofit, gson
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.basgeekball:awesome-validation:4.1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
}
Note: Each drawable is used only once.
The following thread does not solve my problem:
Drawable already belongs to another owner but does not expose a constant state
Problem found: The following attribute is causing the exception:
android:backgroundTint="#000"
If I don't use it, there is a pink background on the FAB :(
Fixed:
Added xmlns:app="http://schemas.android.com/apk/res-auto" in top layout
Used app:backgroundTint="#color/colorFABTint" instead of android:backgroundTint="#000"
Added following line in colors.xml
<color name="colorFABTint">#000000</color>
Resultant xml:
<RelativeLayout
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_marginBottom="5dp"
app:layout_anchorGravity="bottom"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_height="wrap_content"
android:src="#drawable/ic_home_account"
app:backgroundTint="#color/colorFABTint"
android:id="#+id/fbtn_activity_main_account_manage_addresses"
app:layout_anchor="#id/fbtn_activity_main_account_edit_account"/>
Drawable has a state, and if you assign it to more than one Floating Action Button, then there will be a problem keeping track of the Drawable's state.
Maybe there is better solutions but one solution may be to set fab icons in onCreate instead of layout you can remove fab src from layout and use this:
fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).mutate());
or maybe this:
fab.setImageResource(getResources().getDrawable(R.drawable.ic_edit_account).getConstantState().newDrawable());

In ConstraintLayout when I set a layoutDirection of a view to "rtl" some thing go wrong. How to avoid this?

my sample xml file to introduce my problem is 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:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="#string/update_text_view"
android:onClick="updateTextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="274dp" />
</android.support.constraint.ConstraintLayout>
I want my (toBeUpdated) textView to have "rtl" layoutDirection. With this code we have above every thing is ok until the time textView must be updated. After (for any reason) I update this textView at run time the view jump to the left of the Guideline. I found what's wrong. The reason behind this sudden jump is that when direction is right to left so right is the start and left is the end of view (as you know completely reverse of usual). So my new and corrected version of this xml file to solve this issue is
new version of 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:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="#string/update_text_view"
android:onClick="updateTextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="274dp" />
</android.support.constraint.ConstraintLayout>
in this version, at first, textView is in wrong place but after it is updated, it jump where I want. Completely reverse of first situation where the textView was in correct place until It was not updated and after that, jump happens.
In both cases a sudden unwanted jump happen. It may overlaps some other view or be overlapped by them.
And the most important thing is that maybe I don't want it to be updated even one time and that is an static title. What shall I do?
Is this a Bug or something?
build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "example.com.testconstraintlayout"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
}
I can't think of any reason why the text view should jump when the contents are updated. I think that this is a bug and that it is probably related to left/right and start/end confusion that crops up now and again.
You don't show screen shots and I can't be sure of what you are trying to achieve, but I think a work-around for you is to use left/right instead of start/end for the text view as follows:
<TextView
android:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
I have tried this out and the view does not jump as it does with start/end.

Android: Floating Action Button appears with transparent background

I've added FloatingActionButton to my application with a png icon ic_send. When I was testing using gingerbread device it keeps showing the button with no background color, but on lollipop its showing OK.
Here is my Activity code:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import butterknife.Bind;
import butterknife.ButterKnife;
public class MainActivity2 extends AppCompatActivity {
#Bind(R.id.toolbar)Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
}
}
And here is my xml file:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="#layout/toolbar" />
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dp10"
android:background="#color/card"
android:gravity="center"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="#dimen/dp5">
<EditText
android:id="#+id/main_edt_from"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dp30"
android:hint="#string/amount"
android:inputType="numberDecimal" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dp15"
android:src="#drawable/ic_send"
app:elevation="2dp"
app:fabSize="normal"
app:layout_anchor="#id/card"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
My build.gradle config is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.kr.currencyconverter"
minSdkVersion 10
targetSdkVersion 23
versionCode 4
versionName "2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:cardview-v7:23.0.1'
}
What I have tried is adding app:backgroundTint="#color/accent" to the FloatingActionButton but it didn't works.
Here is an image to show what I mean.. in testing I get a transparent button
you must set
app:backgroundTint="#color/yourcolor"
attach this icon here
"#dimen/dp15"
there seems to be background color present in this image.
I had a similar issue with FloatingActionButton(FAB). In my case I was using fragments in Activity and I had FAB in my activity's layout file. So fragment renders on top of FAB. So I had to add fab.bringToFront(); in onPostResume() method in my activity to get it work.
#Override
protected void onPostResume() {
super.onPostResume();
fab.bringToFront(); // fab - reference of FloatingActionButton
}
Also, Check elevation of the layout should be smaller than FAB's elevation.
remove app:elevation="2dp" on FloatingActionButton
<android.support.design.widget.FloatingActionButton
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dp15"
android:src="#drawable/ic_send"
//app:elevation="2dp"
app:fabSize="normal"
app:layout_anchor="#id/card"
app:layout_anchorGravity="bottom|right|end" />
Instead, Use given snippet
<android.support.design.widget.FloatingActionButton
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dp15"
android:src="#drawable/ic_send"
app:fabSize="normal"
app:layout_anchor="#id/card"
app:layout_anchorGravity="bottom|right|end" />

android.support.v7.widget.Toolbar not found (Android Studio)

for round about 2 weeks from now, I receive an error message, whenever I try to preview an .xml design-file in my Android Studio Project. As I am relatively new to the whole topic I'd like to ask whether you have an answer.
The error message:
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.Toolbar
OR
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.CardView
One of the .xml files:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar_tabs"
android:background="#color/primaryColor"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VPlan App RC1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:id="#+id/textView7"
android:layout_marginStart="16dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_refresh"
android:id="#+id/ic_refresh"/>
</RelativeLayout>
<com.astuetz.PagerSlidingTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/primaryColor"
android:textColorPrimary="#color/white"
android:textSize="14sp"
android:id="#+id/tabs"
android:layout_marginTop="?attr/actionBarSize" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Also as it might help, here's the build.gradle file where the support library is located.
The build.grade file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'com.nocomment.vplanehs'
minSdkVersion 10
targetSdkVersion 22
versionCode 16
versionName '0.8.5_RC1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':volley')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
}
In this project we also use volley as well as libraries from ZXing's QR Code reader.
I'd be very thankful if someone could help me. Thank you in advance!

Categories

Resources