I'm trying to style text inTabLayout. I'd like to managed the styles such as font color, size and weight, change the text therein from being set to ALL CAPS
How can I go about it?
TabLayout tabLayout = new TabLayout(this);
tabLayout.addTab(tabLayout.newTab().setText("Upload"));
tabLayout.addTab(tabLayout.newTab().setText("Pics"));
tabLayout.addTab(tabLayout.newTab().setText("Vids"));
tabLayout.addTab(tabLayout.newTab().setText("Papers"));
I would like to attach the TabLayout to styles set in XML: something like:
Then I call it:
Button button = new Button(mContext);
button.setText("Add New BAG");
button.setTextAppearance(R.style.bttn_style);
button.setTextAppearance(R.style.custom_bttn_style);
res/values/styles.xml
<style name="custom_bttn_style" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#00600f</item>
<item name="android:textSize">18dp</item>
<item name="android:fontFamily">\'Zilla Slab\', serif</item>
</style>
Vielen dank im voraus.
You need to inflate a custom view, where you will add all styles you want
View view = LayoutInflater.from(this).inflate(R.layout.icon_tab, null);
AppCompatTextView tv = (AppCompatTextView) view.findViewById(R.id.tab);
ImageView imgTab1 = (ImageView) view.findViewById(R.id.imgTab);
imgTab1.setImageResource(R.drawable.icon_tab_search);
imgTab1.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
tv.setText(titles[0]);
tabLayout.getTabAt(0).setCustomView(view);
Related
how to make center alignment title, message & button
MaterialAlertDialogBuilder(requireContext())
.setTitle("Message")
.setMessage("This is info message.")
.setPositiveButton("Ok") { dialog, which ->
}
.show()
For the the title and the message you can use:
<style name="MaterialAlertDialog__Center" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitlePanelStyle">#style/Title.Panel.Center</item>
<item name="materialAlertDialogBodyTextStyle">#style/Message.Center</item>
</style>
<style name="Title.Panel.Center" parent="MaterialAlertDialog.MaterialComponents.Title.Panel">
<item name="android:gravity">center_horizontal</item>
</style>
<style name="Message.Center" parent="MaterialAlertDialog.MaterialComponents.Body.Text">
<item name="android:gravity">center_horizontal</item>
</style>
with:
MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialog_Center)
.setTitle("Message")
..
.show()
You can create your own layout and add it to your dialog
val inflater=LayoutInflater.from(requireContext())
//Getting the custom view
val view=inflater.inflate(R.layout.YOUR_CUSTOM_LAYOUT,null)
//Obtaining the components
val title=view.findViewById(R.id.YOUR_CUSTOM_TILE)
title.text="Message"
val button=view.findViewById(R.id.YOUR_CUSTOM_BUTTON)
button.setOnCLickListener{
//onClick
}
val dialog=MaterialAlertDialogBuilder(requireContext()).setView(view).create()
dialog.show()
To center the title and message you only have to change this in your Theme
<item name="materialAlertDialogTheme">#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog.Centered</item>
In the simplest way
MaterialAlertDialogBuilder(context, com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
Change to this
MaterialAlertDialogBuilder(requireContext(), com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered))
.setTitle("Message")
.setMessage("This is info message.")
.setPositiveButton("Ok") { dialog, which ->
}
.show()
(I am working with Xamarin C# but the code is identical to Java)
I created a DialogFragment which inflates a custom layout. The OnCreateView looks like this :
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate(Resource.Layout.dialog_feedback, container);
int scale = Context.Resources.DisplayMetrics.HeightPixels;
int height = scale / 2;
Dialog.Window.SetLayout(ViewGroup.LayoutParams.MatchParent, height);
Dialog.Window.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal);
return view;
}
And the OnCreate looks like this :
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle(0, Resource.Style.dialog_no_border);
}
Here's the style :
<style name="dialog_no_border" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
The layout that the dialog is inflating contains a ConstraintLayout as the parent and has a AppCompatEditText inside it.
When i open the dialog and click on the EditText, the keyboard overlaps the Edittext. What i'm trying to do is, when the keyboard pops up, it should push up the DialogFragment and show the EditText above itself. How do i achieve that ?
I tried setting android:windowSoftInputMode="adjustNothing", android:windowSoftInputMode="adjustPan", android:windowSoftInputMode="adjustResize" in the activity tag inside the manifest, but with no luck!
So, how do i achieve this ?
I am trying to apply custom color in AlertDialogue. Its changing text color as well background color in it but not changing SingleChoiceItems text color. You can see it black color in it with page number like below image.
I am using style like below code
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:textColor">#color/TextColorLite</item>
<item name="android:background">#color/colorPrimaryDarkLite</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">?attr/MainAccentColor</item>
<item name="android:buttonBarButtonStyle">#style/DialogButtonStyle</item>
</style>
<style name="DialogButtonStyle" parent="#style/Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">?attr/TextColor</item>
<item name="android:textStyle">bold</item>
</style>
Java Code For Dialoge
AlertDialog.Builder builder = new AlertDialog.Builder(
getActivity(), R.style.AlertDialogTheme);
builder.setTitle("Go to Page:");
builder.setSingleChoiceItems(mPageOptions, mPageIndx - 1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
mOptionDiag.dismiss();
mPageIndx = item + 1;
updateQuotesListServer();
updatePageInfo();
}
});
builder.setNegativeButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
});
mOptionDiag = builder.create();
mOptionDiag.show();
What I should do for change this black text color ?
Thanks
I have got solved adding this items in style.
<!--For List Text-->
<item name="textColorAlertDialogListItem">#color/TextColorLite</item>
<!--For Radio-->
<item name="android:textColorSecondary">#color/TextColorLite</item>
Thanks
In your resources folder open styles.xml and add a custom theme like for example this:
<style name="radiobuttonstyle" parent="Material.Drawable.RadioButton">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/md_green_900</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/md_green_400</item>
<item name="colorControlNormal">#color/md_green_900</item>
<item name="colorControlActivated">#color/md_green_400</item>
</style>
and in your RadioButton in your layout add it as the theme of your RadioButton like this:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioyes"
android:theme="#style/radiobuttonstyle"
android:text="Yes"
android:textColorLink="#color/md_light_green_900"
android:textColorHighlight="#color/md_green_900"
android:textColor="#color/md_light_green_900" />
PS: that is my own custom radio button so it should work.
I have created a custom DialogFragment like it is described in the developer guide.
Now what I am trying to do sounds simple enough, but I cannot get it to work.
I have defined: android:background="#android:color/transparent" in my layout xml which I am loading like this (in my onCreateDialog):
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.pausedialog, null);
setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
As you can see I also tried to set a custom style in the DialogFragment which is defined like this:
<style name="CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:alwaysDrawnWithCache">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And I also tried getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
which leads to a null pointer exception.
I am using android.support.v4.app.DialogFragment. Can this be the cause?
Or am I doing something else wrong?
Try to set style and theme in onCreate method of your dialogFragment class implementation.
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
int style=DialogFragment.STYLE_NO_TITLE;
int theme=android.R.style.Theme_Translucent;
setStyle(style, theme);
}
Or
if you are using Dialog class then you can also set Style and theme on dialog instance.
This worked for me. I created a new style:
<style name="CustomDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
And then set this style in my DialogFragment's onCreate() method like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialog);
}
This is the style I use to totally remove the Dialog`s background.-
<style name="Theme.Dialog" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
As for the Dialog creation, you're creating a DialogBuilder but then you manually inflate a view, I guess that's the problem. Try this instead.-
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customTheme));
AlertDialog dialog = builder.create();
dialog.show();
EDIT
Another approach is extending AlertDialog.-
public class CustomDialog extends AlertDialog {
public DialogParent(Context context) {
super(context, R.style.CustomDialog);
setContentView(R.layout.pausedialog);
// More initialization stuff
}
}
And then 'manually' instantiate it.-
AlertDialog dialog = new CustomDialog(getActivity());
dialog.show();
i want to change icon when click on tabhost
below is the source code
private void setTabs() {
addTab("Home", TabHome.class, R.drawable.home);
addTab("Performers", TabPerformers.class, R.drawable.performers);
addTab("Tickets", TabTickets.class, R.drawable.tickets);
addTab("Info", TabInfo.class, R.drawable.info);
}
private void addTab(String labelId, Class<?> c, int drawableId) {
tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
i want to change tab's icon when user press tab for that i have used below tabhost event
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
#Override
public void onTabChanged(String tabId) {
if (tabId.equals("tabHome")) {
but could not success
there is also a tab_indicater.xml file but from that only background will be change not icon
below is the xml code
<?xml version="1.0" encoding="utf-8"?>
<!-- Non focused states -->
<item android:drawable="#drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="#drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
<!-- Pressed -->
<item android:drawable="#drawable/tab_bg_selector" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="#drawable/tab_press" android:state_pressed="true"/>
below is the screen shot
when we click on any one tab it's icon should be change like here it must become orange..
can any body help me...
There's no straightforward way to change the TabSpec icon. You have to put your icons in the selector drawables.