Reputation: 884
I am trying to change the text colour and font of title "Enter Details" which you can see in below snapshot but was not able to make it. Please help me to solve this problem.
Code:-
public class MainActivity extends Activity {
Button cust;
Dialog custom;
EditText Fname;
EditText Lname;
TextView txt;
Button savebtn;
Button canbtn;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cust = (Button)findViewById(R.id.cusdia);
txt = (TextView)findViewById(R.id.txt);
cust.setOnClickListener(new View.OnClickListener()
{
String fname,lname;
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
custom = new Dialog(MainActivity.this);
custom.setContentView(R.layout.dialog);
Fname = (EditText)custom.findViewById(R.id.fname);
Lname = (EditText)custom.findViewById(R.id.lname);
savebtn = (Button)custom.findViewById(R.id.savebtn);
canbtn = (Button)custom.findViewById(R.id.canbtn);
custom.setTitle("Enter Details");
savebtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
fname = Fname.getText().toString();
lname = Lname.getText().toString();
txt.setText("Your Name is "+fname +lname);
custom.dismiss();
}
});
ALert Dialogue box Snapshot
Upvotes: 8
Views: 156
Reputation: 485
Add following code in style.xml
<style name="MyDialog" parent="@android:style/Theme.Dialog">
<item name="android:typeface">monospace</item>
<item name="android:textColor">#ff4444</item>
</style>
and set your dialog like following
d = new Dialog(Inquiry.this,R.style.MyDialog);
I am sure , you will get what you want.
Upvotes: 2
Reputation: 231
you can use below code.create custom dialog using xml file and avoid default title bar. instead of default title bar you can use textview in xml file.and also use below style in java code.
Dialog dialog = new Dialog(DetailsActivity.this, R.style.FullHeightDialog);
dialog.setContentView(R.layout.insert_text_dialog);
style
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Upvotes: 2
Reputation: 18977
you can simply use
new AlertDialog.Builder(this)
.setCustomTitle(customTitleView)
and for customTitleView
create a view
for example a TextView
and set the font
and color
for it.
Upvotes: 0