ConTeXt: Draw a line under the headertext
As Timothy Li noted, Aditya's solution draws the line on every page. It is possible to define a header (or footer) that only appears on pages with content. For my purposes, I used a footer, but the following code could equally be applied to just the header:
\setuphead[chapter][
header=empty,
]
% Define the appearance for the section name in the footer.
\defineframed[FooterSection][
frame=off,
topframe=on,
align=flushleft,
width=\makeupwidth,
rulethickness=1.6pt,
location=bottom,
foregroundstyle=\tfx\ss,
height=broad,
top={\blank[small]},
]
% Define the appearance of the page number in the footer.
\defineframed[FooterPage][
frame=off,
location=bottom,
foregroundstyle=\tfx\bold\ss,
]
% Include the section name and page number in the footer.
\setupfootertexts
[\FooterSection{\getmarking[section]}]
[\FooterPage{\pagenumber}]
\starttext
\startfrontmatter
\startstandardmakeup
\startalignment[middle]\tfa{Title Page}\stopalignment
\stopstandardmakeup
\setuppagenumbering[conversion=romannumerals]
\setcounter[userpage][1]
\completecontent
\stopfrontmatter
\startchapter [title=alpha] \stopchapter
\startsection[title=alphasec] \stopsection
\startchapter [title=beta] \stopchapter
\startsection[title=alphasec] \stopsection
\startchapter [title=gamma] \stopchapter
\startsection[title=alphasec] \stopsection
\stoptext
Here is one way to do this. Also note that I cleaned up the manner in which you are setting up headertexts.
\setuplayout
[
header=\lineheight,
headerdistance=\lineheight,
]
\setuppagenumbering
[
location=,
alternative=doublesided,
]
\definepagebreak
[chapterpagebreak]
[yes,header,footer,right]
\setuphead
[chapter]
[
style=\bfc,
header=empty,
page=chapterpagebreak,
]
\setupheader[style=bold]
\setupheadertexts
[{\getmarking[sectionnumber]\hskip1em\getmarking[section][first]}]
[pagenumber]
[{Chapter~\getmarking[chapternumber]\hskip1em\getmarking[chapter]}]
[pagenumber]
\setupbackgrounds[header][text][bottomframe=on]
\starttext
\chapter{First Chapter}
this is the first chapter
\page
the second page of the first chapter
\chapter{Second Chapter}
this is the second chapter
\page
the second page of the second chapter
\stoptext
EDIT To get rid of the header on the empty pages use:
\unprotect
\installpagebreakmethod {reallyempty}
{\page_otr_flush_all_floats
\page_otr_command_next_page
\doifnot{\namedlayoutelementparameter\v!header\c!state}\v!stop{\setuplayoutelement[\v!header][\c!state=\v!high]}%
\doifnot{\namedlayoutelementparameter\v!footer\c!state}\v!stop{\setuplayoutelement[\v!footer][\c!state=\v!high]}%
\page_otr_insert_dummy_page}
\protect
\definepagebreak
[chapterpagebreak]
[yes,reallyempty,right]
\setuphead
[chapter]
[
style=\bfc,
header=high,
before={\blank[force,\the\headerheight]},
page=chapterpagebreak,
]