Text Color Not Changing in AlertDialogue - java

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.

Related

Unable to implement shared animation transition

I am trying to implement shared animation transition when someone clicks on recycler view item and navigate to detail activity.I want to show effect on image view when its size increases in detail activity.There is no transition effect is showing.
Below is my code:
themes.xml
<style name="Theme.ITunes" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple</item>
<item name="colorPrimaryVariant">#color/purple_dark</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:windowContentTransitions">true</item>
</style>
item_layout.xml
<ImageView
android:layout_width="200dp"
android:layout_height="170dp"
android:id="#+id/trackImg"
android:scaleType="fitXY"
android:transitionName="imageTransition"/>
activity_video_detail.xml
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/imgDetail"
android:scaleType="fitXY"
android:transitionName="imageTransition"/>
VideoAdapter.class
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(context, VideoDetail.class);
i.putExtra("name",model.getTrackName());
i.putExtra("image",model.getArtworkUrl100());
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context,holder.trackImg,"transition");
context.startActivity(i,options.toBundle());
}
});
VideoDetail.class
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if(item.getItemId() == android.R.id.home){
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBackPressed() {
supportFinishAfterTransition();
}
What can I try to resolve this?
The string passed to makeSceneTransitionAnimation should match transitionName in the receiving activity, so use imageTransition instead of transition
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context,holder.trackImg,"imageTransition");
It's also a good idea to use string resources to get rid of magic strings

How to change font size in TabLayout?

In my application I want to use TabLayout and I use this library:
https://github.com/LiushuiXiaoxia/TabLayoutPlus
However, the text size is big and I want to change it. For this I set custom style in style.xml, but it does not change the text size.
XML Code:
<cn.mycommons.tablayoutplus.library.TabLayoutPlus
android:id="#+id/fullSearch_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/fullSearch_toolbar"
android:background="#color/colorPrimary"
android:paddingBottom="#dimen/size2"
android:paddingLeft="#dimen/size2"
android:paddingRight="#dimen/size2"
app:tabIndicatorColor="#color/whiteMe"
app:tabSelectedTextColor="#color/whiteMe"
app:tabTextAppearance="#style/allCapsTabLayout_search"
app:tabTextColor="#color/unSelectTab" />
<style name="allCapsTabLayout_search" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">#dimen/font5</item>
</style>
How can I change text size?
Go to
1> Your Library Module
2> open a file "tablayoutplus_custom_view.xml"
3> set android:textSize="20sp" into "android:id="#+id/tvTabText""
OR
Set Programatically in Library module in "BadgedTabCustomView.java":
tvTabText.setTextSize(20);
Hope this helps you now.
Use this: use Parent style as parent="Widget.Design.TabLayout"
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<!--<item name="tabMaxWidth">#dimen/tab_max_width</item>-->
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">10dp</item>
<item name="tabPaddingEnd">10dp</item>
<item name="tabBackground">#color/grey_200</item>
<item name="tabTextAppearance">#style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/appred</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#color/grey_800</item>
<item name="textAllCaps">true</item>
</style>
Then apply your style in Tablayout:
<cn.mycommons.tablayoutplus.library.TabLayoutPlus
//
style="#style/MyCustomTabLayout"
// />
(or)
Use this change progrmmatically
for (int i = 0; i < tabLayout.getTabCount(); i++) {
BadgedTabCustomView customView = tabLayout.getTabCustomViewAt(i);
if (customView != null) {
customView.setTabText("Tab" + (i + 1));
customView.setTabCount(i);
customView.setTextSize(20);
}
}
#RedBounce I hope below method work for you. style attribute may be not work in your TabLayout because you have used custome tabview.
<cn.mycommons.tablayoutplus.library.TabLayoutPlus
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
open TabLayoutPlus.java file and find the below method inside this class
private BadgedTabCustomView initTab(TabLayout.Tab tab) {
BadgedTabCustomView customView = new BadgedTabCustomView(getContext());
customView.tvTabText.setTextColor(getTabTextColors());
//add your tab font size here as you want
customView.tvTabText.setTextSize(20);
customView.tvTabSubText.setTextColor(getTabTextColors());
if (subTextSize > 0) {
customView.tvTabSubText.setTextSize(TypedValue.COMPLEX_UNIT_PX, subTextSize);
}
customView.tvTabCount.setTextColor(countTextColor);
if (countTextSize > 0) {
customView.tvTabCount.setTextSize(TypedValue.COMPLEX_UNIT_PX, countTextSize);
}
customView.tvTabCount.setBackgroundDrawable(countTextBackground);
customView.setTabText(tab.getText());
tab.setCustomView(customView);
return customView;
}
just put below line in this method
customView.tvTabText.setTextSize(20); //20 is font size

Can't change AlertDialog items colors

I created multiple alert dialogs in different activities. Now all of sudden the AlertDialog items appear in red !
Here is my code
AlertDialog.Builder builder = new AlertDialog.Builder(this, MyDialogStyle);
builder.setTitle("Select Method :");
final String[] choices = new String[]{"Weight Based", "Body Surface Area"};
builder.setItems(choices, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on choice[which]
switch (choices[which]) {
case "Weight": {
create_item(false);
break;
}
case "Body Surface Area": {
create_item(true);
break;
}
}
}
});
builder.show();
styles.xml (v21)
<style name="MyDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#000000</item>
<item name="android:textColor">#000000</item>
<item name="android:textColorPrimary">#000000</item>
<item name="android:colorPrimary">#000000</item>
<item name="android:colorAccent">#000000</item>
<item name="android:textColorAlertDialogListItem">#000000</item>
<item name="android:textColorSecondary">#000000</item>
<item name="android:text">#000000</item>
<item name="android:textAppearanceListItemSecondary">#000000</item>
<item name="android:textAppearance">#000000</item>
<item name="android:color">#000000</item>
styles.xml
<style name="MyDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#000000</item>
<item name="android:textColor">#000000</item>
<item name="android:textColorPrimary">#000000</item>\
<item name="android:textColorAlertDialogListItem">#000000</item>
<item name="android:textColorSecondary">#000000</item>
<item name="android:text">#000000</item>
<item name="android:textAppearance">#000000</item>
</style>
I tried changing the parent style or deleting it, but both give the same bright red result ! any ideas ?
try use this style ,,, hope it'll work for you
<style name="AlertDialogCustom" parent="#android:style/Theme.Dialog">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">10sp</item>
</style>

How to automatically apply material primary and accent colors to dialog

I have custom theme with changed primary and accent colors. But AlertDialog is not picking up those colors automatically when I create dialog using:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
This is what I get - dialog with default colors:
And this is what I would like to have - dialog with custom colors:
I can create custom AlertDialog theme and apply it during AlertDialog creation:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppTheme_Dialog);
I would like to skip calling constructor with theme parameter.
Is there a way to force custom colors on all themes without deriving them in styles, including AlertDialog base theme?
Minimup API level I have to support is 15.
My activity code
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog();
}
public void dialog()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Dialog");
builder.setMessage("Lorem ipsum dolor ...");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
}
}
My customized style
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
My colors
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Add this in your the App theme:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- your style -->
<item name="alertDialogTheme">#style/AppTheme.Dialog</item>
And then,
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);

How to change the text color of a menu item in Theme.AppCompat.Light.DarkActionBar theme?

I have black background with white letters.
Any ideas?
Thanks.
<style name="PacerTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">#android:color/black</item>
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
</style>
<style name="myCustomMenuTextApearance" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:textColor">#android:color/white</item>
</style>
Normal:
Click in menu button, and show :
Modify the style like this:
<style name="PacerTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
</style>
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/white</item>
</style>
For "myCustomMenuTextApearance" style use for parent
#android:style/TextAppearance.Widget.IconMenu.Item
instead of
#style/Widget.AppCompat.Light.ActionBar.Solid
I found the solution, program change text color, as follows:
#Override
public boolean onPrepareOptionsMenu(Menu menu)
{
for(int i=0; i<menu.size(); i++)
{
MenuItem mi = menu.getItem(i);
String title = mi.getTitle().toString();
Spannable newTitle = new SpannableString(title);
newTitle.setSpan(new ForegroundColorSpan(Color.WHITE), 0, newTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mi.setTitle(newTitle);
}
return true;
}
The XML is as follows:
<style name="PacerTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">#android:color/black</item>
</style>

Categories

Resources