”The civil rights movement was not won by calling Bull Connor a racist,” he said. “He was a racist. But it was won by saying we should be at that lunch counter.”

Mr. Garcetti said that during a visit to Washington, Los Angeles officials met with Gary Cohn, the president’s top economic adviser, about getting a share of the public works investment program Mr. Trump has pledged to propose. Mr. Brown, in a recent Washington visit, met with Elaine Chao, the secretary of transportation, to lobby for support for a high-speed rail project.

“I know some people feel very strongly, so I don’t want to minimize their ardor,” Mr. Brown said while in Washington. “At the same time, we want to work with Mr. Trump. If it isn’t a trillion dollars, it’s tens of billions that California can get.”

Democrats are trying to balance the powerful anti-Trump sentiment among Democratic voters with the awareness of the threats California now faces with the Trump Administration, captured most recently by the failed health care bill, which would cost the state close to $20 billion in aid. At the same time, they are trying to figure out the extent to which Mr. Trump responds to the traditional tools of a political negotiation: Compromise, cajoling and threat.

Rob Stutzman, a longtime California Republican strategist who led an anti-Trump movement last year, said Democrats were at risk of provoking a backlash that could hurt the state.

“The Democrats have to be careful of overreach,” he said. “A statewide sanctuary law, that’s an overreach. That’s exposing a lot of their members to a bad vote.”

A poll of California residents last month by the Institute of Governmental Studies at the University of California at Berkeley found that 53 percent opposed state and local governments being permitted to ignore requests from federal authorities to detain illegal immigrants. But even though Mr. Trump is extraordinarily unpopular in this state, Californians, by a margin of 53 to 37 percent, said state leaders should work with him when they disagree with him, rather than risk consequences of pure defiance.