[英]Change text selection color for TextArea in Flex 4 for programmatic selection
我正在使用Flex 4 spark TextArea,並實現了搜索字段。 我使用以下代碼突出顯示TextArea中的搜索文本:
private function findAndHighlightText():void
{
var text:String = findTextInput.text;
var beginIndex:int = scriptSourceTextArea.text.indexOf( text, m_lastFoundIndex );
if (beginIndex == -1 && m_lastFoundIndex > 0)
{
// We are at the end, search back from the begin
Alert.show( resourceManager.getString( 'groovyresources', 'search.at.end' ),
resourceManager.getString( 'groovyresources', 'find' ) );
m_lastFoundIndex = 0;
beginIndex = scriptSourceTextArea.text.indexOf( text, m_lastFoundIndex );
}
if (beginIndex != -1)
{
var endIndex:int = beginIndex + text.length;
m_lastFoundIndex = endIndex;
scriptSourceTextArea.selectRange( beginIndex, endIndex );
scriptSourceTextArea.scrollToRange( beginIndex );
}
else
{
Alert.show( resourceManager.getString( 'groovyresources', 'search.not.found', [text] ),
resourceManager.getString( 'groovyresources', 'find' ) );
}
}
最重要的是TextArea上的selectRange
方法。 這將突出顯示TextArea中的文本,但我想使用其他顏色。
我可以通過應用CSS樣式的focused-text-selection-color
更改加亮顏色以進行手動選擇(請參見http://www.kirupa.com/forum/showthread.php?354479-Change-highlight-color-for-text -fields ),但這不會更改程序選擇的顏色。
更新:對於程序選擇,顏色不會更改,因為TextArea此時沒有焦點。 因此,我需要找到未聚焦的選擇顏色CSS名稱。
有兩種樣式會影響在Flex中突出顯示所選文本的方式:
.scriptSourceTextArea {
focused-text-selection-color: #788ec5;
unfocused-text-selection-color: #7e94cb;
}
一個用於焦點,另一個用於文本區域沒有焦點時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.