创建自定义文本选择操作

时间:2017-01-31 01:05:22

标签: android

我想长按并选择一些文字,我可以在许多应用中看到它,但我对此没有任何想法。我正在寻找一些想法或一些例子? 以下图片是我的目标。

What I want

2 个答案:

答案 0 :(得分:3)

不确定您要找的是什么。

  • 如果您只是愿意让<TextView ... android:textIsSelectable="true"/> 选择,请确保它看起来像这样:

    pennies = 10
    nickels = 10
    dimes = 10
    quarters = 10
    
    quarters_spent = 0
    dimes_spent = 0
    nickels_spent = 0
    pennies_spent = 0
    
    print("\nWelcome to change-making program.")
    in_str = input("\nEnter the purchase price (xx.xx) or `q' to quit: ")
    
    while in_str.lower() != 'q':
        dollar_str, cents_str = in_str.split(".")
    
        if in_str.lower() == 'q':
            quit()
    
        in_int = int(float(in_str) * 100)
    
        if in_int < 0:
            print("Error: purchase price must be non-negative.")
            in_str = input("\nEnter the purchase price (xx.xx) or `q' to quit: ")
    
        if in_int > 0:
            payment = input("\nInput dollars paid: ")
            payment_int = int(float(payment) * 100)
            change = payment_int - in_int
    
            #determines if there payment input
            if payment_int < in_int:
                print("Error: Insufficient payment.")
                payment = input("\nInput dollars paid: ")
                payment_int = int(float(payment) * 100)
                change = payment_int - in_int
    
    
            if change == 0:
                print("No change.")
    
            #determines how many quarters, dimes, nickels, and pennies are left
            while change >= 25 and quarters > 0:
                change = change - 25
                quarters_spent += 1
                quarters = quarters - quarters_spent
    
            while change >= 10 and dimes > 0:
                change = change - 10
                dimes_spent += 1
                dimes = dimes - dimes_spent
    
            while change >= 5 and nickels > 0:
                change = change - 5
                nickels_spent += 1
                nickels = nickels - nickels_spent
    
            while change >= 1 and pennies > 0:
                change = change - 1
                pennies_spent += 1
                pennies = pennies - pennies_spent
    
    
    
            if quarters == 0 and dimes == 0 and nickels == 0 and pennies == 0:
                print("Error: ran out of coins.")
                quit()
    
            print("\nCollect Payment Below:")
            if quarters_spent > 0:
                print(quarters_spent, "Quarters")
            if dimes_spent > 0:
                print(dimes_spent, "Dimes")
            if nickels_spent > 0:
                print(nickels_spent, "Nickels")
            if pennies_spent > 0:
                print(pennies_spent, "Pennies")
    
            print("\nStock: ", quarters, "Quarters, ", dimes, " Dimes, ", nickels, " Nickels, ", pennies, " Pennies ")
    
            in_str = input("\nEnter the purchase price (xx.xx) or `q' to quit: ")
    
            pennies = pennies
            nickels = nickels
            dimes = dimes
            quarters = quarters
    

    已经回答了here

  • 但是,如果您要查找的是自定义文字选择操作,那么幸运的是,Ian Lake A GREAT TUTORIALthis one这样做。

    如果你是图书馆,你可以在 Github 上查看one

    您可能也会查看一些相关问题。如果是,请在 Stackoverflow 上查看此enter image description here

答案 1 :(得分:0)

在xml文件中,添加以下内容:

android:textIsSelectable="true"