Step 1: Create a new project and name it AnalogAndDigitalExample Below is the final output, download code and step by step tutorial: īelow is the example of Analog and Digital Clock in Android in which we display a simple analog and digital clock by using their different properties and perform click event on them so whenever a user click on a clock the name of the clock is displayed by using a Toast. If we need to use two or more styles for a digital clock then “|” operator is used for that.īelow we set the bold and italic text styles for text of a digital clock. textStyle : textStyle attribute is used to set the text style of a digital clock. tTextSize(25) // set size for displayed textĥ. Setting textSize of DigitalClock In Java class: DigitalClock simpleDigitalClock = (DigitalClock)findViewById(R.id.simpleDigitalClock) // initiate a digital clock We can set the text size in sp(scale independent pixel) or dp(density pixel).īelow we set the 40sp size for the text of a digital clock. textSize: textSize attribute is used to set the size of text of a digital clock. tTextColor(Color.RED) // red text color for displayed textĤ. Setting textColor of Digital Clock In Java class: DigitalClock simpleDigitalClock = (DigitalClock)findViewById(R.id.simpleDigitalClock) // initiate a digital clock Color value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.īelow we set the red color for the displayed text of a digital clock. textColor: textColor attribute is used to set the color of the text of a digital clock. gravity: The gravity attribute is an optional attribute which is used to control the alignment of the text like left, right, center, top, bottom, center_vertical, center_horizontal etc.īelow we set the right gravity for text of a digital clock. īelow we set the 30dp padding from all the sides of the digital clock. Padding: padding attribute is used to set the padding from the all side’s of the digital clock.paddingBottom: padding bottom attribute is used to set the padding from the bottom side of the digital clock.paddingTop: padding top attribute is used to set the padding from the top side of the digital clock.paddingLeft: padding left attribute is used to set set the padding from the left side of the digital clock.paddingRight: padding right attribute is used to set the padding from the right side of the digital clock.Important Note: Padding attribute has no effect on analog clock. padding: padding is an attribute used to set the padding from left, right, top or bottom side of the digitalclock. Now let’s we discuss some attributes of digital clock or text clock and they are not used for analog clock:ġ. tBackgroundColor(Color.GREEN) // green color for the background of the analog clock Setting background In Java class: AnalogClock simpleAnalogClock = (AnalogClock)findViewById(R.id.simpleAnalogClock) // inititate a analog clock In below code we use background attribute to set the Green color for the background of a analog clock. The background color can also be set in java class using setBackgroundColor() method. You can set a color or a drawable in the background. background: background attribute is used to set the background of a analog, digital or text clock. Below is an example code with explanation included, in which we set the id of a analog clock. id:id is an attribute used to uniquely a analog or digital clock. Now let’s we describe some common and important attributes that helps us to configure analog, text or digital clock in xml file (layout).ġ. If we use text clock in our app then it require minimum API level 17. Text Clock is a widget same as Digital Clock but as in API level 17 digital clock is deprecated so we have to use text clock instead of digital clock. Below is the description of Text clock in android. From API level 17 you can use TextClock instead of digital clock. Important Note: Digital clock is deprecated in version “ API 17 “.
0 Comments
Leave a Reply. |