Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am so sorry for the delay; I wasn't at home. I am sending herewith style.xml and color.xml Please help me Thanks Dan Could you

I am so sorry for the delay; I wasn't at home. I am sending herewith style.xml and color.xml

Please help me

Thanks

Dan

Could you please help me on this Android Java Mobile Program. Thanks for your help

Exercise 7-5 Use colors In this exercise, youll modify the Tip Calculator app presented in this chapter so it uses custom colors. 1. Start Android Studio and open the project named ch07_ex5_TipCalculator.

1. Open the colors.xml file in the values directory. This file defines several custom colors.

2. Open the styles.xml file in the values directory. This file customizes the default theme.

3. Open the layout for the app in the graphical editor. This layout should use the colors from Androids built-in themes.

4. Modify the styles.xml file so the theme named AppTheme sets the windowBackground attribute of the theme to the custom color named background.

5. View the layout in the graphical editor. The background color for the window should now be light green.

6. Modify the styles.xml file so the theme named AppTheme sets the attributes named textColorPrimary and textColorSecondary to the custom color named white.

7. View the layout in the graphical editor. The text color for the TextView and TextEdit widgets should now be white, but the text color for the Buttons should still be black.

8. Modify the styles.xml file so the style named TextView.Label sets the textColor attribute to the color named black.

9. View the layout in the Graphical Layout editor. The text color for the labels should now be black.

This is the program .xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:padding="10dp" >    <TextView  android:id="@+id/billAmountLabel"  style="@style/TextView.Label"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="@string/bill_amount_label" /> <EditText  android:id="@+id/billAmountEditText"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignBaseline="@+id/billAmountLabel"  android:layout_marginLeft="5dp"  android:layout_toRightOf="@+id/billAmountLabel"  android:ems="8"  android:inputType="numberDecimal"  android:text="@string/bill_amount" > <requestFocus /> EditText>    <TextView  android:id="@+id/percentLabel"  style="@style/TextView.Label"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignLeft="@+id/billAmountLabel"  android:layout_below="@+id/billAmountLabel"  android:text="@string/tip_percent_label" /> <TextView  android:id="@+id/percentTextView"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignBaseline="@+id/percentLabel"  android:layout_alignLeft="@+id/billAmountEditText"  android:padding="5dp"  android:text="@string/tip_percent" /> <Button  android:id="@+id/percentDownButton"  android:layout_width="45dp"  android:layout_height="45dp"  android:layout_alignBaseline="@+id/percentTextView"  android:layout_marginLeft="25dp"  android:layout_toRightOf="@+id/percentTextView"  android:text="@string/decrease" /> <Button  android:id="@+id/percentUpButton"  android:layout_width="45dp"  android:layout_height="45dp"  android:layout_alignBaseline="@+id/percentDownButton"  android:layout_toRightOf="@+id/percentDownButton"  android:text="@string/increase" />    <TextView  android:id="@+id/tipLabel"  style="@style/TextView.Label"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignLeft="@+id/percentLabel"  android:layout_below="@+id/percentLabel"  android:text="@string/tip_amount_label" /> <TextView  android:id="@+id/tipTextView"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignBaseline="@+id/tipLabel"  android:layout_alignLeft="@id/billAmountEditText"  android:padding="5dp"  android:text="@string/tip_amount" />    <TextView  android:id="@+id/totalLabel"  style="@style/TextView.Label"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignLeft="@+id/tipLabel"  android:layout_below="@+id/tipLabel"  android:text="@string/total_amount_label" /> <TextView  android:id="@+id/totalTextView"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignBaseline="@+id/totalLabel"  android:layout_alignLeft="@+id/tipTextView"  android:padding="5dp"  android:text="@string/total_amount" /> RelativeLayout> 

This is the java file

package com.murach.tipcalculator; import java.text.NumberFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.app.Activity; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class TipCalculatorActivity extends Activity implements OnEditorActionListener, OnClickListener { // define variables for the widgets  private EditText billAmountEditText; private TextView percentTextView; private Button percentUpButton; private Button percentDownButton; private TextView tipTextView; private TextView totalTextView; // define the SharedPreferences object  private SharedPreferences savedValues; // define instance variables that should be saved  private String billAmountString = ""; private float tipPercent = .15f; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tip_calculator); // get references to the widgets  billAmountEditText = (EditText) findViewById(R.id.billAmountEditText); percentTextView = (TextView) findViewById(R.id.percentTextView); percentUpButton = (Button) findViewById(R.id.percentUpButton); percentDownButton = (Button) findViewById(R.id.percentDownButton); tipTextView = (TextView) findViewById(R.id.tipTextView); totalTextView = (TextView) findViewById(R.id.totalTextView); // set the listeners  billAmountEditText.setOnEditorActionListener(this); percentUpButton.setOnClickListener(this); percentDownButton.setOnClickListener(this); // get SharedPreferences object  savedValues = getSharedPreferences("SavedValues", MODE_PRIVATE); } @Override public void onPause() { // save the instance variables  Editor editor = savedValues.edit(); editor.putString("billAmountString", billAmountString); editor.putFloat("tipPercent", tipPercent); editor.commit(); super.onPause(); } @Override public void onResume() { super.onResume(); // get the instance variables  billAmountString = savedValues.getString("billAmountString", ""); tipPercent = savedValues.getFloat("tipPercent", 0.15f); // set the bill amount on its widget  billAmountEditText.setText(billAmountString); // calculate and display  calculateAndDisplay(); } public void calculateAndDisplay() { // get the bill amount  billAmountString = billAmountEditText.getText().toString(); float billAmount; if (billAmountString.equals("")) { billAmount = 0; } else { billAmount = Float.parseFloat(billAmountString); } // calculate tip and total  float tipAmount = billAmount * tipPercent; float totalAmount = billAmount + tipAmount; // display the other results with formatting  NumberFormat currency = NumberFormat.getCurrencyInstance(); tipTextView.setText(currency.format(tipAmount)); totalTextView.setText(currency.format(totalAmount)); NumberFormat percent = NumberFormat.getPercentInstance(); percentTextView.setText(percent.format(tipPercent)); } @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) { calculateAndDisplay(); } return false; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.percentDownButton: tipPercent = tipPercent - .01f; calculateAndDisplay(); break; case R.id.percentUpButton: tipPercent = tipPercent + .01f; calculateAndDisplay(); break; } } } 

Style.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">      <item name="android:textViewStyle">@style/TextViewitem> <item name="android:editTextStyle">@style/EditTextitem> <item name="android:buttonStyle">@style/Buttonitem> style>   <style name="TextView"  parent="@android:style/Widget.TextView"> <item name="android:textSize">20spitem> style> <style name="EditText" parent="@android:style/Widget.EditText"> <item name="android:textSize">20spitem> style> <style name="Button" parent="@android:style/Widget.Button"> <item name="android:textSize">20spitem> <item name="android:textStyle">bolditem> style>   <style name="TextView.Label"> <item name="android:textStyle">bolditem> <item name="android:padding">10dpitem> style> resources> 

Color.xml

xml version="1.0" encoding="utf-8"?> <resources> <color name="primary">#141315color> <color name="secondary">#736C6Bcolor> <color name="tertiary">#DDE0CEcolor> <color name="background">#A6D39Dcolor> <color name="dark">#000000color> <color name="light">#FFFFFFcolor> resources> 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago