How can I theme my action bar to match this image? - android

I'm working on an app's UI and I want to get the action bar to look like this:
This is what it looks like right now:
This is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/sunshine_blue</item>
<item name="colorPrimaryDark">#color/sunshine_dark_blue</item>
</style>
<!-- Main activity theme -->
<style name="ForecastTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.NoTitle</item>
</style>
<!-- Detail activity theme -->
<style name="DetailTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.Title</item>
</style>
<!-- Settings activity theme -->
<style name="SettingsTheme" parent="AppTheme">
</style>
<!-- Main activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/ic_logo</item>
</style>
<!-- Detail activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.Title" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/art_clear</item>
</style>
<!-- style for item selected on phone -->
<style name="ForecastListStyle">
<item name="android:choiceMode">none</item>
</style>
</resources>
This is the layout file for my detail activity:
<!-- Master layout -->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
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:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="24sp"
android:id="#+id/detail_day_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_date_textview" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="96sp"
android:paddingStart="32dp"
android:paddingLeft="32dp"
android:id="#+id/detail_high_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="48sp"
android:textColor="#color/fragment_detail_grey"
android:paddingStart="64dp"
android:paddingLeft="64dp"
android:id="#+id/detail_low_textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detail_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="22sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_forecast_textview" />
</LinearLayout>
</LinearLayout>
<!-- Humidity, wind, pressure -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_humidity_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_pressure_textview" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_wind_textview" />
</LinearLayout>
</ScrollView>
And this is my AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.sunshine.app" >
<!-- This permission is necessary in order for Sunshine to perform network access. -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:theme="#style/ForecastTheme"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:theme="#style/DetailTheme"
android:label="#string/title_activity_detail"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/SettingsTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<provider
android:authorities="com.example.android.sunshine.app"
android:name=".data.WeatherProvider" >
</provider>
</application>
</manifest>
I've tried a couple different things in the displayOptions but can't seem to get the logo and "Details" text to display at the same time. Also, is there any way to get the arrow to match? Or does this just depend on the API level?
Thanks for any help!

It's better to use menu item in toolbar/app bar.
in this way there will be no additional space or any dislocate item in action bar .
<menu 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"
tools:context=".MainActivity">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:orderInCategory="100"
android:title="#string/action_share"
app:showAsAction="always" />
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="101"
android:title="#string/action_search"
app:showAsAction="always" />
<item
android:id="#+id/action_settings"
android:orderInCategory="102"
android:title="#string/action_settings"
app:showAsAction="never" /> </menu>
And just remember using toolbar is much more easier for your purpose
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
Here's complete tutorial

Related

Why does my app not fill the entire screen?

Here I have 2 screenshots
The top one is my app. The 2nd one is facebook. Notice how facebook takes up the entire screen while mine is just short of reaching the top and bottom. How can I get my app to fill the entire screen, or atleast have it extend to right under the time and battery percentage?
Styles XML file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textAllCaps">false</item>
<item name="navigationViewStyle">#style/Widget.Design.NavigationView</item>
</style>
<style name="AppTheme.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
<item name="android:textColorSecondary">#color/colorWhite</item>
<item name="android:textColorPrimary">#color/colorWhite</item>
</style>
Layout XML file
<?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">
<ImageView
android:id="#+id/btnApply"
android:layout_width="0dp"
android:layout_height="50dp"
android:contentDescription="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#color/colorPrimary" />
<TextView
android:id="#+id/txtApplyButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:gravity="center_horizontal"
android:text="APPLY"
android:textColor="#color/colorWhite"
app:fontFamily="#font/varela"
app:layout_constraintBottom_toBottomOf="#+id/btnApply"
app:layout_constraintEnd_toEndOf="#+id/btnApply"
app:layout_constraintStart_toStartOf="#+id/btnApply"
app:layout_constraintTop_toTopOf="#+id/btnApply" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/txtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:hint="#string/first_name"
android:inputType="textPersonName"
android:maxLength="30"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/txtLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:hint="#string/last_name"
android:inputType="textPersonName"
android:maxLength="30"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<TextView
android:id="#+id/txtLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Locations"
android:textColor="#color/colorGray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtLocation">
<ImageView
android:id="#+id/btnAddLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:contentDescription="#null"
app:srcCompat="#drawable/ic_add_black_24dp" />
<ImageView
android:id="#+id/btnRemoveLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:contentDescription="#null"
app:srcCompat="#drawable/ic_delete_black_24dp" />
<Spinner
android:id="#+id/spnrLocations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<ImageView
android:id="#+id/imgVerified"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtVerified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="#font/varela"
android:textColor="#color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/imgVerified"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</ScrollView>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:icon="#drawable/ic_home_black_24dp">
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".EmailSignUp" />
<activity android:name=".EmailVerification" />
<activity android:name=".EmailSignIn" />
<activity android:name=".Home" />
<activity android:name=".AddLocation" />
<activity android:name=".InstantMessage" />
<activity android:name=".ProcessPayment" />
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
Use this one theme
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textAllCaps">false</item>
</style>
You can do this programmatically
You need to set up
getWindow().getDecorView().setSystemUiVisibility(flag);
Setup these flags inside onWindowFocusChanged of your activity (onWindowFocusChanged
mainly used for fullscreen so you can retain your fullscreen even after focus change. you can also set flags in your onCreate or where you like)
in your activity you can do like
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//You can also pass multiple flags as i did. one for hide navigation one for make layout stable
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
}
}
}
For Extra there is also other flags that change system ui like flag for fullscreen.
here you can find all flags. just search for system_ui_flag
I woke up this morning, tried running it again, and everything looked fine. I changed absolutely nothing. Android studio/my phone must have a mind of it's own.

toolbar shows in the IDE, but does not show on the emulator

I am working on an app I tried adding the back button but the toolbar does not show on the emulator again. Here is my code.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".SplashTimer"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".VerificationActivity">
<activity android:name=".MainActivity" />
</activity>
<activity android:name=".DashboardActivity" />
<activity
android:name=".LoginActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".ProblemsActivity" />
<activity
android:name=".TotalActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".FirstPayment" />
<activity android:name=".FirstPaymentInformation" />
<activity android:name=".DeclineQuestionsActivity" />
<activity android:name=".LIkelyProblemsActivity" />
<activity
android:name=".TotalAmountActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".ThanksActivity" />
<activity
android:name=".SignUpActivity"
android:theme="#style/SignUpTheme" />
<activity android:name=".StripePayment" />
<activity
android:name=".PaymentActivity"
android:label="#string/title_activity_payment"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".LocationActivity" />
<activity android:name=".SecondPayment" />
<activity android:name=".DriverPayment"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
style.css
<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>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
<style name="SignUpTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorHint">#bdbdbd</item>
<item name="android:windowBackground">#color/colorWhite</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
myActivity
public class DashboardActivity extends AppCompatActivity {
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() == null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
public void mechanicFN (View view){
Intent intent = new Intent(DashboardActivity.this, LIkelyProblemsActivity.class); // Create an Intent
startActivity(intent); // Move to Verification Activity
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.logout){
SharedPreferences preferences = getSharedPreferences("Mypref", 0);
preferences.edit().clear().commit();
Intent intent = new Intent(DashboardActivity.this, HomeActivity.class); // Create an Intent
startActivity(intent); // Move to Verification Activity
Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
R.layout.activity_dashboard
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:id="#+id/activity_dashboard"
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"
android:background="#color/colorBackground"
tools:context="com.example.system2.tranxav.DashboardActivity">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/cv"
android:layout_marginRight="8dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/mechanic"
android:onClick="mechanicFN"
android:id="#+id/imageView2" />
<TextView
android:text="Hire a Mechanic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView2"
android:gravity="center"
android:layout_marginBottom="16dp"
android:textColor="#000"
android:id="#+id/textView2" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:id="#+id/cv1"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/toyin_van"
android:id="#+id/imageView3" />
<TextView
android:text="Toyin Van"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView3"
android:gravity="center"
android:textColor="#000"
android:layout_marginBottom="16dp"
android:id="#+id/textView3" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/cv3"
android:layout_marginRight="8dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/spareparts"
android:onClick="mechanicFN"
android:id="#+id/imageView4" />
<TextView
android:text="Spare Parts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView4"
android:gravity="center"
android:layout_marginBottom="16dp"
android:textColor="#000"
android:id="#+id/textView4" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:id="#+id/cv5"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/electrician"
android:id="#+id/imageView5" />
<TextView
android:text="Auto Electrician"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView5"
android:gravity="center"
android:textColor="#000"
android:layout_marginBottom="16dp"
android:id="#+id/textView5" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
enter image description here
I browsed through the code but I cant figure out where the problem is. I have tried removing the toolbar on the activity but it did not work.
Add theme to your Activity.
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
In Manifest
<activity
android:name=".DashBoardActivity"
android:label="#string/title_activity_payment"
android:theme="#style/AppThemeNoActionBar" />
And modify onCreate() as.
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}

2 almost identical activities in 2 projects, but 1 doesn't have toolbar

When I normally create a new project, the activities have toolbars on top like this:
But somehow, I'm a noob so I managed to somehow delete this action bar by modifying the styles xml the Activity and the manifest. So now it's a fullscreen activity, even when I use DarkActionBar as parent in styles:
Here my files:
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swagdev.app.swagpoints">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Map"/>
</application>
Activity:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swagdev.app.swagpoints.MainActivity">
<com.journeyapps.barcodescanner.BarcodeView
android:layout_width="300dp"
android:layout_height="300dp"
app:zxing_use_texture_view="true"
android:id="#+id/scanner"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/location_field"
android:textSize="30sp"
android:layout_below="#+id/scanner"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<TextView
android:text="Scan Sticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvh"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="menu"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</FrameLayout>
</nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout>
</RelativeLayout>
SO now my toolbar is gone. How do i need to modify styles or activity or manifest to get it back?

CheckBox colour not changing

I have a CheckBox and I don't know how to change its colours.
I tried creating a custom style in styles.xml and styles21.xml
I added there:
<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">#color/white100</item>
<item name="android:textColorSecondary">#color/white87</item>
</style>
then I added the style to my CheckBox, as:
#style/checkBoxStyle
No change in the colour. Its still black and I want it white.
Tried creating another checkbox, cuz I taught I might have messed the previous one. Same result.
manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InputTaskActivity"
android:windowSoftInputMode="stateVisible">
</activity>
</application>
XML with the checkbox inside:
<?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="55dp"
android:layout_margin="5dp"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:textColor="#color/white100"
android:textSize="18sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox3"
style="#style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Change the style attribute to theme as follows:
<CheckBox
android:id="#+id/checkBox3"
android:theme="#style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
You might have to create a new theme with the new accent color. Then you have to specify the newly created theme in the manifest for the activity your checkbox is located in.
CheckBox style in res/values/styles
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/colorGreen</item>
<item name="colorControlActivated">#color/colorBlue</item>
</style>
res/values/colors.xml
<color name="colorBlue">#022ce6</color>
<color name="colorGreen">#02e602</color>
in your actvitiy XML file
<CheckBox
android:id="#+id/checkBox3"
android:theme="#style/MyCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

Android custom style/scheme is not applied correctly to button-textColor

I'm having trouble with applying a custom scheme(style) to certain views. I have defined my own style in res/values/styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
I have applied this style to the main activity of my simple test application, like this
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/myStyle1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
The layout of the MainActivity contains a couple of buttons, some textViews, some of them have the style attribute spiecified explicitly, others should be inhertiting it from the whole activity.
<?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:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/silver"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="#string/edit_message" />
<Button android:id="#+id/send_button"
style="#style/myStyle1"
android:text="#string/button_send" />
<Button android:id="#+id/relative_activity"
android:text="#string/rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#color/red"
android:text="#string/button_TTT" />
<fragment android:name="my.firstapp.Fragment1"
android:background="#color/red"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
As far as I can tell, everything in the activity should be stylized according to the style I ahve defined, however, this is what I get
As you can see, only the buttons with the specified style have their text in red, the other two don't. However, even the white buttons get the correct font from the scheme, so at least some of it is being applied. Why not all of it? Any help would be appreciated, I'm thoroughly confused.
If you want a global style for all your buttons you need to do something like this.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:buttonStyle">#style/myStyle1</item>
</style>
</resources>
In your android manifest you should set the theme...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
You can do the same thing for checkboxs etc. More information from this link.
http://developer.android.com/reference/android/R.attr.html
Also I tested this on the following layout. All 3 buttons should have red text.
<?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:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffaaaaaa"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="edit_message" />
<Button android:id="#+id/send_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button_send" />
<Button android:id="#+id/relative_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#ffff0000"
android:text="button_TTT" />
<!--<fragment android:name="my.firstapp.Fragment1"
android:background="#00ff0000"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />-->
</LinearLayout>

Categories

Resources