DHAKA, Bangladesh (AP) _ President Hussain Ershad said today he would lift martial law after a parliament is elected, and promised to relax the ban on political activities soon.

On Wednesday, he appointed seven new ministers, bringing the number in the Cabinet to 21. He also named three state ministers and one deputy minister. Two of the new Cabinet ministers are opposition leaders - Kazi Zafar Ahmed of the United People's Party and Sirakuul Hossain Khan of the Democratic Party.

''Martial law will be withdrawn on the first sitting of an elected parliament but indoor political activities will be allowed soon,'' Ershad told reporters before departing for a visit to China.

Ershad said he would announce his decision on resumption of ''indoor political activities'' after his return next Wednesday. He apparently will continue the ban on mass rallies.

Parliamentary elections have been scheduled several times, but each time the mainstream opposition of 23 parties has said it would boycott them if martial law were not lifted first.

On March 1, Ershad responded by banning all political activities.

He called a referendum for March 21, and the government said it gave him a 94 percent confidence vote to continue his moderate military rule until national elections could be held.

Ershad said today he would not hesitate to contest a presidential election if the people desired.

''But I have not taken any decision as yet on the schedule of presidential or parliamentary polls. The subject is open to discussion with the politicians,'' he said.

Ershad, who assumed power in a bloodless coup in March 1982, reaffirmed his intention to hold a dialogue with opposition politicians in an effort to achieve a national consensus to return to democracy through national elections.

Also named to the new Cabinet were Air Vice Marshal K. M. Aminul Islam, Dr. M.A. Matin, Korban Ali and Abdus Sattar, from the ruling People's Party, and the seventh is career diplomat Humayun Rasheed Chowdhury, who has been Ershad's foreign affairs adviser.

The portfolios of the new ministers were not announced.

One of the new state ministers also is from the opposition. The deputy minister is Sheik Shahidul Islam, nephew of the nation's first president, Sheik Mujibur Rahman, who led Bangladesh to independence in 1971 and later was assassinated.