Skip to content

Latest commit

 

History

History
60 lines (54 loc) · 4.39 KB

KeyValueView.md

File metadata and controls

60 lines (54 loc) · 4.39 KB

KeyValueView

A view containing 2 TextViews in a vertical LinearLayout, one will show a heading or a key, the other one will show its value. By default, the key is slightly larger and has properties so that it signifies more emphasis.

Usage

Assuming you already have configured jitpack and added the dependency for this library in your project gradle files, simply add this in your layout to include it.

<com.corphish.widgets.ktx.KeyValueView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"/>

Properties supported

  • app:keyText : Sets the Key text. Can be a text or a string resource (recommended).
  • app:valueText : Sets the Value text. Can be a text or a string resource (recommended).
  • app:keySize : Sets the text size of Key. Default is 17sp.
  • app:valueSize : Sets the text size of Value. Default is 13sp.
  • app:keyEnabled : Sets the Key enabled if its true, false otherwise. Default value is true for obvious reasons.
  • app:valueEnabled : Sets the Value enabled if its true, false otherwise. Default is true for obvious reasons. Note: If both Key and Value are disabled, the entire view is disabled, that means any event listeners set for the entire view will not work for example.
  • app:keyStyle : Sets the style specified to Key. Default is Normal.
  • app:valueStyle : Sets the style specified to Value. Default is Normal.
  • app:absoluteSpacing : Sets the line spacing between the Key and Value with the value specified. There are 2 spacings here, one below the Key and other above the Value. Default is 1dp + 1dp.
  • app:absoluteSpacingTop : Sets the line spacing above Value, spacing below the key is unaffected. Default is 1dp.
  • app:absoluteSpacingBottom : Sets line spacing below Key. Line spacing above Value is unaffected. Default is 1dp.
  • app:relativeSpacing, app:relativeSpacingTop, app:relativeSpacingBottom : Use these properties to increase/decrease the spacing if you do not choose to use absolute spacing.
  • app:keyTextColor : Sets text color of Key. Default is the default text color of your theme.
  • app:valueTextColor : Sets text color of Value. Default is the default text color of your theme.
  • app:keyBackgroundColor : Sets background color of Key. Default is transparent.
  • app:valueBackgroundColor : Sets background color of Value. Default is transparent.
  • app:methodForValue : The method that is executed and the return value of it is set as the Value text. You need to provide full path of the method, that is including the package name, class (and subclasses if present), and then the method name (see this). If however the method is present in the Activity source which contains the layout containing the KeyValueView, then you can only specify the method name (see this). The method must return String and must be fairly simple. If you are doing some long running or complex task, then you might consider setting values programmatically.

Methods

Most of the methods are used up by properties. See the source file for reference. Additionally there are getKeyTextView() and getValueTextView() methods which return the respective TextViews, on which you can do other TextView actions that it supports.

Screenshot

Code
<com.corphish.widgets.ktx.KeyValueView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        app:keyText="@string/app_name"
        app:valueText="Test value"
        app:keyTextColor="@color/colorPrimary"
        app:keyStyle="bold|italic"
        app:methodForValue="getText"
        app:valueBackgroundColor="@color/colorAccent"/>  
        

<com.corphish.widgets.ktx.KeyValueView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        app:keyText="Oh god please work?"
        app:valueText="Test value"
        app:keyStyle="bold"
        app:methodForValue="com.corphish.keyvalueviewtest.TextHelper.getSomeText"/>
Result